sequence
An image sequence scrubbed by scroll, frame by frame, from a poster <img>.
Live preview needs WebGPU or WebGL 2. A gold pocket watch whose crystal and bow lift away frame by frame while the frame stays pinned and you scroll.
This example failed to draw.
Usage
Put it on img, the poster frame. start() registers sequence, 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 sequence<div class="explode"> <img class="watch" src="/media/landing/watch/01.avif" width="800" height="800" data-dio="sequence" data-dio-frames="/media/landing/watch/{01..36}.avif" /></div>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.watch', 'sequence', { by: 'pin', start: 0, end: 1, frame: 0, blend: false, ease: 0, cache: 6,})import { start } from '@dioramajs/diorama'import sequence from '@dioramajs/media/sequence'
const app = start()app.attach('.watch', sequence({ by: 'pin', start: 0, end: 1, frame: 0, blend: false, ease: 0, cache: 6,}))Page transitions
Fades with the page transition; a keyed flight carries the frame shown at the time. 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 |
|---|---|---|---|
framesrebuildsdata-dio-frames | string | '' | Frame URLs by commas, or a range like /seq/{0001..0096}.webp padded as its first number. |
atlasrebuildsdata-dio-atlas | string | '' | Atlas pages instead of frames, a range or list; cells read left to right, top to bottom. |
gridrebuildsdata-dio-grid | [number, number]1 to 16 | [1, 1] | Columns and rows of cells on an atlas page. |
countrebuildsdata-dio-count | number | 'auto'1 to 2000 | 'auto' | Number of frames; auto takes all of the range, or every cell of every atlas page. |
byrebuildsdata-dio-by | 'pin' | 'progress' | 'manual' | 'pin' | What drives the frame: pin of the sticky section, viewport progress, or frame alone. |
startdata-dio-start | number0 to 1 | 0 | Progress at which the first frame shows. |
enddata-dio-end | number0 to 1 | 1 | Progress at which the last frame shows. |
framedata-dio-frame | number0 to 100 | 0 | Frame shown when by is manual, for a tween or a slider; with blend a fraction mixes two. |
blenddata-dio-blend | boolean | false | Mix neighboring frames by the fraction of the index. |
easedata-dio-ease | number0 to 1 s | 0 | Smoothing of the index behind scroll; 0 follows scroll at once (Lenis already smooths it). |
cachedata-dio-cache | number1 to 32 | 6 | Decoded frames kept around the current one, two of them ahead in the scroll direction.At most low 2, medium 4 by quality tier. |
densityrebuildsdata-dio-density | number0.1 to 1 | 1 | Share of the frames loaded: 0.5 loads every second one and the others show the nearest.At most low 0.5 by quality tier. |
resolutionrebuildsdata-dio-resolution | number320 to 3840 px | 1920 | Longest side in px a frame is decoded at; larger frames shrink while decoding.At most low 960, medium 1440 by quality tier. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
It reads delta
. Draws only while something on it moves, then stops. Scroll draws its own frames; a frame that finishes decoding asks for one, and ease keeps drawing until the index settles. 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 <img> shows its poster and not a single frame is downloaded. The poster is what people with reduced motion and without WebGL see, so choose it on purpose; another still frame for them is a <picture> with <source media="(prefers-reduced-motion: reduce)">.
Runs on every device. Works as on desktop: scroll drives it.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { sequence: { reducedMotion: 'static' } } })Cost and quality
- Download
- 3.8 KB min+gzip the first time a page uses it
- GPU
- Two texture reads per pixel of the box; one upload of the frame per drawn frame at most.
- Memory
- The compressed bytes of every frame it loads, cache decoded frames on the CPU and one texture of a frame on the GPU (two with blend). An atlas holds its pages instead, .webp, .avif or .ktx2 images, and compressed .ktx2 pages take 4 to 8 times less GPU memory. Under Save-Data or on 2G it loads a quarter of the frames at up to 960 px.
- 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 | Every second frame, up to 2 decoded frames at up to 960 px. |
medium | Up to 4 decoded frames, decoded at up to 1440 px. |
Recipes
Take a product apart on scroll
The usual page is a tall section with a sticky stage the height of the screen. sequence plays over the pin of that section, so 400vh gives the frames three screens of scroll. An end below 1 shows the last frame early and holds it while the reader takes in the heading.
<section class="explode" data-dio-section style="height: 400vh"> <div class="stage" style="position: sticky; top: 0; height: 100vh" > <img src="/seq/watch/01.avif" data-dio="sequence" data-dio-frames="/seq/watch/{01..72}.avif" data-dio-end="0.85" /> <h2 data-dio="text-reveal" data-dio-trigger="scroll" >Eleven parts, one hand.</h2> </div></section>The <img> is the poster: it shows before the first frame decodes, without WebGL and with reduced motion. Make it the frame that tells the story on its own.
Pack a short sequence into an atlas
Eighteen frames in two pages of 3 × 3 cost two requests instead of eighteen. A sparse set like this steps from frame to frame, and blend mixes neighbors by the fraction of the index, so it still moves smoothly. Here progress drives it, with no sticky stage: the watch opens while the frame crosses the middle of the viewport.
Live preview needs WebGPU or WebGL 2. The pocket watch from an atlas of eighteen frames, blended, opening as the frame crosses the middle of the viewport.
This example failed to draw.
<div class="explode"> <img class="watch" src="/media/landing/watch/01.avif" width="800" height="800" data-dio="sequence" data-dio-atlas="/media/landing/watch-atlas-{0..1}.avif" data-dio-grid="3 3" data-dio-blend="true" data-dio-by="progress" data-dio-start="0.25" data-dio-end="0.75" /></div>Atlas pages can be .ktx2 too. Compressed pages take 4 to 8 times less GPU memory than .avif or .webp, which matters for long sequences on phones.
Drive the frame from a tween
With by set to manual the scroll leaves it alone and frame picks the frame. Tween it with GSAP, tie it to a range input, or play it on a button.
const watch = app.effects.get( document.querySelector('.watch'), 'sequence',)gsap.to(watch.params, { frame: 35, duration: 2.4, ease: 'power2.inOut',})Notes
Each frame decodes off the main thread and only a window of cache frames stays decoded around the current one, two of them ahead in the scroll direction. A fast fling skips frames rather than stalling, and the nearest decoded frame shows meanwhile. On the low tier it loads every second frame, and under Save-Data or on 2G a quarter of them at up to 960 px.
Without data-dio-section, the section is the parent of the closest sticky ancestor. Add the attribute when the markup differs, for example when ScrollTrigger pins the stage, and on the section of any sticky stage whose copies should hold still while it is pinned. A pinned stage holds the canvas still during native scroll only when it fills half the viewport or more.
The sequence is decoration over a poster, so it needs no controls of its own. Put what the frames show into the alt of the <img> or into the text next to it: a screen reader reads that, never the frames.