split-flap
A departure board: each character flips through a drum of letters to its own, on view and whenever the site changes the text.
Departures
- LISBON14:05ON TIME
- OSLO14:20DELAYED
- VALENCIA14:45BOARDING
Live preview needs WebGPU or WebGL 2. A departures board of three flights whose statuses flip to new values every few seconds.
This example failed to draw.
Usage
Put it on a short line of text: a destination, a status, a price, a time, a menu item. Not img, video, canvas, svg or form fields. start() registers split-flap, 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 split-flap<div class="sf-board"> <p class="sf-head">Departures</p> <ol class="sf-rows"> <li> <span>LISBON</span> <span>14:05</span> <span class="sf-status" data-dio="split-flap" data-dio-trigger="change" aria-live="polite" >ON TIME</span> </li> <li> <span>OSLO</span> <span>14:20</span> <span class="sf-status" data-dio="split-flap" data-dio-trigger="change" aria-live="polite" >DELAYED</span> </li> <li> <span>VALENCIA</span> <span>14:45</span> <span class="sf-status" data-dio="split-flap" data-dio-trigger="change" aria-live="polite" >BOARDING</span> </li> </ol></div>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.sf-status', 'split-flap', { style: 'tiles', motion: 'drum', duration: 0.07, flips: 10, stagger: 0.03, delay: 0, threshold: 0.2, tile: '#1c1c1f', gap: 0.08, shade: 0.5,})import { start } from '@dioramajs/diorama'import splitFlap from '@dioramajs/text/split-flap'
const app = start()app.attach('.sf-status', splitFlap({ style: 'tiles', motion: 'drum', duration: 0.07, flips: 10, stagger: 0.03, delay: 0, threshold: 0.2, tile: '#1c1c1f', gap: 0.08, shade: 0.5,}))Page transitions
The copy fades with the page. 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 | 'tiles' | 'plain' | 'tiles' |
|
motionrebuildsdata-dio-motion | 'drum' | 'random' | 'drum' |
|
triggerrebuildsdata-dio-trigger | 'view' | 'change' | 'view' |
|
charsrebuildsdata-dio-chars | string | 'board' | Characters on the drum: board (A to Z, digits and . , : - / &), letters, digits, time, or your own string in order. Characters not on it are dropped in at the end of the flips. |
durationdata-dio-duration | number0 to 0.3 s | 0.07 | Time of one flip; 0 swaps the letters without flipping. |
flipsdata-dio-flips | number0 to 40 | 10 | Most flips per character; 0 or 1 flips straight to the new letter. |
staggerdata-dio-stagger | number0 to 0.3 s | 0.03 | Delay between neighboring characters that flip. |
delaydata-dio-delay | number0 to 2 s | 0 | Wait after the text enters, 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. |
tiledata-dio-tile | color | '#1c1c1f' | Color of the tiles; the letters take the color of the text. |
gapdata-dio-gap | number0 to 0.5 em | 0.08 | Space between neighboring tiles. |
shadedata-dio-shade | number0 to 1 | 0.5 | Shadow on a turning flap, the slit and the lighter top half; 0 is flat. |
seedrebuildsdata-dio-seed | number1 to 100 | 1 | Picks the random faces; the same seed plays 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 delta, reducedMotion and size
. Draws only while something on it moves, then stops. Only while flaps turn; none at rest. How a frame is decided.
Reduced motion and touch
With reduced motion it shows a still frame: motion inputs are zero and time stands still. Static: the tiles stay, and new text shows at once without flips. The plain style is the text as it is.
Runs on every device. The same as with a mouse.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { 'split-flap': { reducedMotion: 'off' } } })Cost and quality
- Download
- 9.2 KB min+gzip the first time a page uses it
- GPU
- One instanced draw of three quads per character, one texture read per pixel.
- Memory
- A small sheet of the drum and the letters of the text, kept while the element lives.
- 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 | The letters are drawn at 1 device pixel per CSS pixel instead of 2. |
Recipes
A status your code changes
Write the new text into the element and the board flips to it: the effect watches the text, so there is no extra call. Only the characters that differ turn, and the DOM always holds the current text, so screen readers, search and copy see it. Add aria-live="polite" if a screen reader should announce each change; it then reads the new status once, not every flip.
<span class="status" data-dio="split-flap" data-dio-trigger="change" aria-live="polite">ON TIME</span>document.querySelector('.status').textContent = 'BOARDING'data-dio-trigger="change" shows the text at once and flips only on changes. The default view also flips the board in from blank tiles the first time it comes into view.
A countdown that ticks every second
For a clock, a launch countdown or a sale timer, use the time drum with data-dio-flips="1": each changed digit turns once, straight to the next value, the way a flip clock does.
<time class="clock" data-dio="split-flap" data-dio-trigger="change" data-dio-chars="time" data-dio-flips="1">02:14:09</time>Menu boards and prices without tiles
data-dio-style="plain" flips the letters alone, in your own font and color, and shows the real text at rest. With motion="random" every letter shows a few random faces and they all land together.
<h2 data-dio="split-flap" data-dio-style="plain" data-dio-motion="random" data-dio-flips="6">Today: ramen</h2>Notes
The tiles look best in a monospaced font with some letter-spacing and a line-height of 1.3 or more, so neighboring tiles and lines do not touch. Each tile is centered on its letter; a space stays a gap. The letters take the color of the text and the tiles take tile; shade="0" gives flat tiles, gap="0" tiles that touch.
chars sets the drum, the order a flap walks through: board (the letters A to Z, digits and . , : - / &), letters, digits, time, or your own string. Lowercase letters stop at the place of their capital, and a character not on the drum drops in at the end. A letter takes as many flips as it is far from its target along the drum, at most flips, so a line settles unevenly like a real board. duration="0" swaps the letters without turning.
With the tiles the board stays drawn at rest, and the DOM text under it stays in the page for screen readers and selection. Under reduced motion the tiles stay and new text shows at once; the plain style is the text as it is. style, motion, trigger, chars and seed rebuild the effect when they change; the other params change live.