assemble
Thousands of lit particles fly out of the depth around the page and gather into a heading.
Planetarium · Winter season
Every star has a place
Forty minutes under a full dome, narrated live by our astronomers. Shows nightly at 7 and 9.
Live preview needs WebGPU or WebGL 2. A planetarium headline that gathers out of a cloud of lit particles floating in front of and behind the page.
This example failed to draw.
Every switch and slider plays it again.
Usage
Put it on a large heading or a short line of display text. Not img, video, canvas, svg or form fields. Text with text-shadow, a text stroke, background-clip: text or vertical writing stays as it is. start() registers assemble, so the attribute alone puts it on an element. The tabs below are the example above, with the values you set.
To change its code, copy the source into your effects folder; the copy replaces the built-in.
npx @dioramajs/diorama add assemble<div class="as-hero"> <p class="as-kicker">Planetarium · Winter season</p> <h2 class="as-headline" data-dio="assemble" data-dio-color="#e4ecff" data-dio-accent="#8fd3ff" >Every star has a place</h2> <p class="as-lede">Forty minutes under a full dome, narrated live by our astronomers. Shows nightly at 7 and 9.</p></div>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.as-headline', 'assemble', { style: 'dots', from: 'scatter', dot: 2.2, duration: 1.4, stagger: 0.03, spread: 1, delay: 0, threshold: 0.2, color: '#e4ecff', accent: '#8fd3ff',})import { start } from '@dioramajs/diorama'import assemble from '@dioramajs/text/assemble'
const app = start()app.attach('.as-headline', assemble({ style: 'dots', from: 'scatter', dot: 2.2, duration: 1.4, stagger: 0.03, spread: 1, delay: 0, threshold: 0.2, color: '#e4ecff', accent: '#8fd3ff',}))Page transitions
Leaving a page, the text breaks back into particles that fly off into the depth; entering, they gather again. How a flight flies.
Params
Every param is also an attribute, and both app.attach() and the handle take it by name.
| Param | Type | Default | Description |
|---|---|---|---|
stylerebuildsdata-dio-style | 'dots' | 'squares' | 'dashes' | 'dots' |
|
fromrebuildsdata-dio-from | 'scatter' | 'below' | 'center' | 'edges' | 'scatter' |
|
triggerrebuildsdata-dio-trigger | 'view' | 'scroll' | 'hover' | 'view' |
|
densityrebuildsdata-dio-density | number0.3 to 3 | 1 | Particles per area of the glyphs; 2 doubles them, up to the tier limit.At most low 0.6 by quality tier. |
dotdata-dio-dot | number1 to 6 px | 2.2 | Size of a particle once it has landed. |
durationdata-dio-duration | number0.3 to 4 s | 1.4 | Flight time of one particle from its start to its place. |
staggerdata-dio-stagger | number0 to 0.2 s | 0.03 | Delay between neighboring letters, so they fill in reading order. |
spreaddata-dio-spread | number0 to 3 | 1 | How far from the text particles start; with the hover trigger, the pointer reach. |
delaydata-dio-delay | number0 to 2 s | 0 | Wait after the trigger, for a cascade. |
thresholddata-dio-threshold | number0 to 1 | 0.2 | Share of the element height in view, above the bottom tenth, before it plays. |
colordata-dio-color | color | 'currentColor' | Color of the particles in flight; currentColor keeps the color of the text. |
accentdata-dio-accent | color | 'currentColor' | Second color shimmering through particles in flight; currentColor for none. |
seedrebuildsdata-dio-seed | number1 to 100 | 1 | Picks the starts, paths and sizes; the same seed gathers the same way. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
It reads height, presence, progress, size and y
. Draws only while something on it moves, then stops. Only while particles fly, while scrolling with the scroll trigger and while lifted beads settle with the hover trigger; none at rest. How a frame is decided.
Reduced motion and touch
With reduced motion it is off and the element shows as plain HTML. Off: the text is shown as it is, and the engine does not load for it.
Runs on every device. The same as with a mouse; with the hover trigger the beads follow a finger while it presses on the heading.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { assemble: { reducedMotion: 'static' } } })Cost and quality
- Download
- 11.6 KB min+gzip the first time a page uses it
- GPU
- One instanced draw of up to 14,000 small quads, and one instanced draw of a quad per letter for the crisp text.
- Memory
- A canvas of the text at twice its CSS size, and about 80 bytes per particle: about 1.1 MB at the high tier.
- Frames
- Idle at rest
It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.
| Tier | What changes |
|---|---|
low | A quarter of the particles, density at most 0.6, and the text rastered at 1 device pixel per CSS pixel instead of 2. |
medium | About half of the particles. |
Recipes
A heading made of beads
With data-dio-trigger="hover" the heading gathers once and then stays made of particles instead of handing back to the text. The beads under the pointer lift towards the viewer, part a little and spring back into place when it moves on; on a touch screen they follow a finger while it presses on the heading. An accent color tints the beads that are lifted. Move the pointer across the heading below.
Made of stardust
Move the pointer across the heading, or press and drag on a touch screen.
Live preview needs WebGPU or WebGL 2. A dark band with a heading of glossy beads that lift towards the viewer under the pointer and spring back.
This example failed to draw.
<section class="as-touch"> <h2 class="as-touch-title" data-dio="assemble" data-dio-trigger="hover" data-dio-accent="#ff8fd8" data-dio-dot="2.6" >Made of stardust</h2> <p class="as-touch-note">Move the pointer across the heading, or press and drag on a touch screen.</p></section>spread sets how far the pointer reaches, in multiples of 80 px. The text stays real for screen readers, search and selection, but it shows as particles, so keep this trigger for a short display line rather than a heading people need to read at a glance.
Section headings that form on scroll
With data-dio-trigger="scroll" a heading gathers as it rises towards the middle of the viewport, holds there as plain text, and breaks up again as it moves on towards the top. Streaks from both sides suit a tech product page; scrolling back plays it in reverse.
<h2 data-dio="assemble" data-dio-trigger="scroll" data-dio-style="dashes" data-dio-from="edges">Signal and noise</h2>Gold leaf for a launch or an award
Tiles that tumble and catch the light, rising from below the heading, read like gold leaf or glitter. A warm color gives them their own tint in flight; they settle into the color of the text.
<h1 data-dio="assemble" data-dio-style="squares" data-dio-from="below" data-dio-dot="3" data-dio-color="#ffcf6e">Launch day</h1>Notes
The particles are small objects in the 3D space around the page, seen through the same camera as the page itself. Those in front of the page are larger, brighter and a little out of focus, those far behind it smaller and dimmer, and their paths bend through depth on the way in. Each one is lit from the upper left: beads show a highlight, tiles glint as they turn.
Their positions come from the pixels of the heading’s own text, drawn the way the browser laid it out, and they take their color from the text, so mixed colors and weights inside the heading carry over. The real text fades in over the particles of each letter as it fills, and once the last letter is in the element is plain, selectable DOM text. Text on screen when the page opens is hidden until the effect is ready and then gathers, as with text-reveal.
The number of particles follows the area of the glyphs: about 5,000 for a 128 px heading of three words, at most 14,000 on fast devices, fewer on slower ones. density raises or lowers it within that limit, and dot sets the size they land at. Under reduced motion the effect is off and the text shows at once. Text with text-shadow, -webkit-text-stroke, background-clip: text or a vertical writing mode stays as it is, with a warning in development. style, from, trigger, density and seed rebuild the effect when they change.