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

scramble

TextAlso inScroll scenes

@dioramajs/text/scrambleSource

Headings and labels decode into place: each letter cycles through random glyphs before it settles.

View as Markdown
On this page

Incident response, automated

Ship the fix before the page goes out.

Live preview needs WebGPU or WebGL 2. An incident tool headline whose letters flicker through random glyphs and lock in from left to right.

This example failed to draw.

When the text scrolls into view, its letters appear one after another as random glyphs that flicker a few times a second and then lock into the real letters, left to right like a terminal decoding a message. Other motions show every letter scrambled at once and settle them in a random order, or add a brief red and cyan split and jitter, like a glitching screen. When the last letter settles the element is the real text again: selectable, crisp and styled by your CSS. With the hover trigger a label stays as it is and scrambles again each time the pointer or keyboard focus reaches it.

Every switch and slider plays it again.

Params of scramble
motion

decode settles letters left to right, each scrambling in turn, for most headings.

by

letter gives each letter its own turn.

Usage

Put it on a heading, a label, a link or a button with text. Not img, video, canvas, svg or form fields. start() registers scramble, 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 scramble
<div class="sc-hero">
<p class="sc-kicker">Incident response, automated</p>
<h2
class="sc-headline"
data-dio="scramble"
>Ship the fix before the page goes out.</h2>
</div>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.sc-headline', 'scramble', {
motion: 'decode',
by: 'letter',
duration: 0.6,
stagger: 0.03,
delay: 0,
cycle: 0.06,
threshold: 0.2,
})
import { start } from '@dioramajs/diorama'
import scramble from '@dioramajs/text/scramble'
const app = start()
app.attach('.sc-headline', scramble({
motion: 'decode',
by: 'letter',
duration: 0.6,
stagger: 0.03,
delay: 0,
cycle: 0.06,
threshold: 0.2,
}))

Page transitions

Leaving a page, the settled letters scramble again in reverse order and go; entering, they decode in order. How a flight flies.

Params

Every param is also an attribute, and both app.attach() and the handle take it by name.

ParamTypeDefaultDescription
motionrebuildsdata-dio-motion'decode' | 'random' | 'glitch''decode'
  • decode settles letters left to right, each scrambling in turn, for most headings.
  • random scrambles every letter at once and settles them in a random order, for numbers and codes.
  • glitch decodes with a red and cyan split and a jitter, for a louder tech look.
byrebuildsdata-dio-by'letter' | 'word''letter'
  • letter gives each letter its own turn.
  • word lets the letters of a word settle together.
triggerrebuildsdata-dio-trigger'view' | 'scroll' | 'hover''view'
  • view plays when the text enters.
  • scroll ties it to the scroll position, both ways.
  • hover plays it each time the pointer or focus reaches it.
charsrebuildsdata-dio-charsstring'mixed'Glyph set: mixed, latin, upper, digits, hex, binary, symbols, or your own string.
durationdata-dio-durationnumber0 to 3 s0.6Time one letter scrambles before it settles.
staggerdata-dio-staggernumber0 to 0.3 s0.03Delay between neighboring letters or words in their turn order.
delaydata-dio-delaynumber0 to 2 s0Wait after the trigger, for a cascade.
cycledata-dio-cyclenumber0.02 to 0.3 s0.06Time each random glyph shows before the next one.
thresholddata-dio-thresholdnumber0 to 10.2Share of the element height in view, above the bottom tenth, before it plays.
seedrebuildsdata-dio-seednumber1 to 1001Picks the random glyphs and order; 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 height, presence, progress, size and y . Draws only while something on it moves, then stops. Only while letters scramble, and with the scroll trigger while scrolling; 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, except that the hover trigger needs keyboard focus on touch.

To change what reduced motion does, patch it in start().

import { start } from '@dioramajs/diorama'
start({ effects: { scramble: { reducedMotion: 'static' } } })

Cost and quality

Download
9.2 KB min+gzip the first time a page uses it
GPU
Two instanced draws of a quad per letter, one or three texture reads per pixel.
Memory
A canvas of the text at twice its CSS size with mip levels, and a small sheet of the glyph set, 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 text and the glyphs are rastered at 1 device pixel per CSS pixel instead of 2.

Recipes

With data-dio-trigger="hover" a link stays as plain text and scrambles each time the pointer or keyboard focus reaches it. Keep duration and stagger short so a short label settles before the visitor clicks. Hover the links below.

Live preview needs WebGPU or WebGL 2. Four navigation links of a studio site that scramble when hovered or focused.

This example failed to draw.

<ul class="sc-nav">
<li>
<a
href="/work"
data-dio="scramble"
data-dio-trigger="hover"
data-dio-stagger="0.02"
data-dio-duration="0.3"
>Work</a>
</li>
<li>
<a
href="/services"
data-dio="scramble"
data-dio-trigger="hover"
data-dio-stagger="0.02"
data-dio-duration="0.3"
>Services</a>
</li>
<li>
<a
href="/studio"
data-dio="scramble"
data-dio-trigger="hover"
data-dio-stagger="0.02"
data-dio-duration="0.3"
>Studio</a>
</li>
<li>
<a
href="/contact"
data-dio="scramble"
data-dio-trigger="hover"
data-dio-stagger="0.02"
data-dio-duration="0.3"
>Contact</a>
</li>
</ul>

A number that settles in a random order

motion="random" shows every letter scrambled at once and locks them in a random order. With chars="digits" it suits a figure on a fintech or crypto page, such as a balance or a block height.

<p
class="stat"
data-dio="scramble"
data-dio-motion="random"
data-dio-chars="digits"
data-dio-duration="0.4"
>$4,812,330</p>

A louder headline for a launch

motion="glitch" adds a red and cyan split and a small jitter while letters scramble, and lets the split fade out as each one settles. Moving by word with a longer stagger keeps it readable.

<h2
data-dio="scramble"
data-dio-motion="glitch"
data-dio-by="word"
data-dio-stagger="0.12"
>Zero trust. Zero downtime.</h2>

Notes

chars takes a named set, mixed, latin, upper, digits, hex, binary or symbols, or any string of your own, such as chars="01" or chars="▖▗▘▙▚▛▜▝▞▟". The random glyphs use the font and color of the element, and each one is narrowed a little to fit the slot of the letter it stands for, so the line does not shift while it plays.

The element keeps its text as you wrote it, with no span per letter, so screen readers, search engines and find in page see the real words. While letters scramble a CSS filter hides the DOM text without removing it, and when the last one settles the element is real, selectable text again. Under reduced motion the effect is off and the text shows at once.

Text on screen when the page opens is hidden until the effect is ready and then plays, as with text-reveal. In the scroll and hover modes it stays as it is instead.

The canvas cannot draw background-clip: text, text-shadow, -webkit-text-stroke, underlines or vertical writing modes the way the browser does. An element with any of the first four keeps its text as it is, and a warning in development names the reason; an underline is hidden while the letters scramble.

Keep it to headings, labels and short lines: over 1500 letters it stays as plain text. motion, by, trigger, chars and seed rebuild the effect when they change.