Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

assemble

Thousands of lit particles fly out of the depth around the page and gather into a heading.

View as Markdown
On this page

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.

When the heading scrolls into view, a cloud of small glossy beads drifts in front of and behind the page, larger and softer the closer it is to the viewer, then streams along curved paths into the shapes of the letters, left to right, and settles without overshoot. As each letter fills, the real text fades in over its particles, so the heading ends as selectable DOM text with no jump. Tiles that tumble and glint, or streaks of light, can stand in for the beads, and the cloud can rise from below, burst out of a point deep behind the heading or pour in from both sides. With the hover trigger the heading stays made of beads, and the ones under the pointer or a finger lift towards the viewer and spring back.

Every switch and slider plays it again.

Params of assemble
style

dots are glossy beads lit from the upper left, for most headings.

from

scatter starts from a cloud around the heading, in front of and behind the page.

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.

Terminal window
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.

ParamTypeDefaultDescription
stylerebuildsdata-dio-style'dots' | 'squares' | 'dashes''dots'
  • dots are glossy beads lit from the upper left, for most headings.
  • squares are flat tiles that tumble and glint, like glitter or gold leaf.
  • dashes are streaks of light along the motion, for a fast tech look.
fromrebuildsdata-dio-from'scatter' | 'below' | 'center' | 'edges''scatter'
  • scatter starts from a cloud around the heading, in front of and behind the page.
  • below rises from under it.
  • center bursts out of a point deep behind its middle.
  • edges pours in from both sides.
triggerrebuildsdata-dio-trigger'view' | 'scroll' | 'hover''view'
  • view gathers when the heading enters.
  • scroll gathers it towards the middle of the viewport and scatters it again above.
  • hover keeps it as beads the pointer lifts.
densityrebuildsdata-dio-densitynumber0.3 to 31Particles per area of the glyphs; 2 doubles them, up to the tier limit.At most low 0.6 by quality tier.
dotdata-dio-dotnumber1 to 6 px2.2Size of a particle once it has landed.
durationdata-dio-durationnumber0.3 to 4 s1.4Flight time of one particle from its start to its place.
staggerdata-dio-staggernumber0 to 0.2 s0.03Delay between neighboring letters, so they fill in reading order.
spreaddata-dio-spreadnumber0 to 31How far from the text particles start; with the hover trigger, the pointer reach.
delaydata-dio-delaynumber0 to 2 s0Wait after the trigger, for a cascade.
thresholddata-dio-thresholdnumber0 to 10.2Share of the element height in view, above the bottom tenth, before it plays.
colordata-dio-colorcolor'currentColor'Color of the particles in flight; currentColor keeps the color of the text.
accentdata-dio-accentcolor'currentColor'Second color shimmering through particles in flight; currentColor for none.
seedrebuildsdata-dio-seednumber1 to 1001Picks 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.

TierWhat changes
lowA quarter of the particles, density at most 0.6, and the text rastered at 1 device pixel per CSS pixel instead of 2.
mediumAbout 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.