scramble
Headings and labels decode into place: each letter cycles through random glyphs before it settles.
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.
Every switch and slider plays it again.
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.
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.
| Param | Type | Default | Description |
|---|---|---|---|
motionrebuildsdata-dio-motion | 'decode' | 'random' | 'glitch' | 'decode' |
|
byrebuildsdata-dio-by | 'letter' | 'word' | 'letter' |
|
triggerrebuildsdata-dio-trigger | 'view' | 'scroll' | 'hover' | 'view' |
|
charsrebuildsdata-dio-chars | string | 'mixed' | Glyph set: mixed, latin, upper, digits, hex, binary, symbols, or your own string. |
durationdata-dio-duration | number0 to 3 s | 0.6 | Time one letter scrambles before it settles. |
staggerdata-dio-stagger | number0 to 0.3 s | 0.03 | Delay between neighboring letters or words in their turn order. |
delaydata-dio-delay | number0 to 2 s | 0 | Wait after the trigger, for a cascade. |
cycledata-dio-cycle | number0.02 to 0.3 s | 0.06 | Time each random glyph shows before the next one. |
thresholddata-dio-threshold | number0 to 1 | 0.2 | Share of the element height in view, above the bottom tenth, before it plays. |
seedrebuildsdata-dio-seed | number1 to 100 | 1 | Picks 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.
| Tier | What changes |
|---|---|
low | The text and the glyphs are rastered at 1 device pixel per CSS pixel instead of 2. |
Recipes
Navigation links that decode on hover
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.
<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.