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

split-flap

TextAlso inMaps and data

@dioramajs/text/split-flapSource

A departure board: each character flips through a drum of letters to its own, on view and whenever the site changes the text.

View as Markdown
On this page

Departures

  1. LISBON14:05ON TIME
  2. OSLO14:20DELAYED
  3. 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.

The statuses change every few seconds from a script; only the letters that change flip.
Params of split-flap
style

tiles draws each character on a split tile in the tile color, also at rest.

motion

drum walks the drum in order, so each letter takes as many flips as it is far from its target, up to flips.

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.

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

ParamTypeDefaultDescription
stylerebuildsdata-dio-style'tiles' | 'plain''tiles'
  • tiles draws each character on a split tile in the tile color, also at rest.
  • plain flips the letters alone and shows the real text at rest.
motionrebuildsdata-dio-motion'drum' | 'random''drum'
  • drum walks the drum in order, so each letter takes as many flips as it is far from its target, up to flips.
  • random shows flips random faces on every letter, so they land together.
triggerrebuildsdata-dio-trigger'view' | 'change''view'
  • view flips in from blank when the text enters, then on every change.
  • change shows the text as it is and flips only when it changes.
charsrebuildsdata-dio-charsstring'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-durationnumber0 to 0.3 s0.07Time of one flip; 0 swaps the letters without flipping.
flipsdata-dio-flipsnumber0 to 4010Most flips per character; 0 or 1 flips straight to the new letter.
staggerdata-dio-staggernumber0 to 0.3 s0.03Delay between neighboring characters that flip.
delaydata-dio-delaynumber0 to 2 s0Wait after the text enters, for a cascade.
thresholddata-dio-thresholdnumber0 to 10.2Share of the element height in view, above the bottom tenth, before it plays.
tiledata-dio-tilecolor'#1c1c1f'Color of the tiles; the letters take the color of the text.
gapdata-dio-gapnumber0 to 0.5 em0.08Space between neighboring tiles.
shadedata-dio-shadenumber0 to 10.5Shadow on a turning flap, the slit and the lighter top half; 0 is flat.
seedrebuildsdata-dio-seednumber1 to 1001Picks 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.

TierWhat changes
lowThe 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>

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.