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

text-glitch

TextAlso inScroll scenes

@dioramajs/text/text-glitchSource

A heading glitches in depth: it breaks into slabs that jump at the viewer, then snaps back flat.

View as Markdown
On this page

Live from Studio 9 · Friday 23:00

Signal lost

Four hours of broken beats, tape loops and analog noise.

Live preview needs WebGPU or WebGL 2. A live music night headline that breaks into slabs jumping at the viewer every few seconds, with red and cyan layers parting in depth.

This example failed to draw.

Switch the style and the trigger, or move the sliders. With trigger hover, point at the heading; on a phone, tap it.
Params of text-glitch
style

rgb tilts the line and parts its color layers.

trigger

interval every few seconds.

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 text-glitch, 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 text-glitch
<section class="tg-hero">
<p class="tg-kicker">Live from Studio 9 · Friday 23:00</p>
<h2
class="tg-title"
data-dio="text-glitch"
data-dio-trigger="interval"
data-dio-interval="2.5"
>Signal lost</h2>
<p class="tg-sub">Four hours of broken beats, tape loops and analog noise.</p>
</section>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.tg-title', 'text-glitch', {
style: 'rgb',
trigger: 'interval',
strength: 1,
split: 6,
slices: 5,
interval: 2.5,
duration: 0.7,
seed: 1,
})
import { start } from '@dioramajs/diorama'
import textGlitch from '@dioramajs/text/text-glitch'
const app = start()
app.attach('.tg-title', textGlitch({
style: 'rgb',
trigger: 'interval',
strength: 1,
split: 6,
slices: 5,
interval: 2.5,
duration: 0.7,
seed: 1,
}))

Page transitions

Leaving a page the slabs fly at the viewer and drop out one by one; entering they fall back into place. 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'rgb' | 'slice' | 'vhs''rgb'
  • rgb tilts the line and parts its color layers.
  • slice extrudes blocks.
  • vhs is a hologram.
triggerrebuildsdata-dio-trigger'hover' | 'interval' | 'scroll' | 'load''hover'
  • hover on pointer, focus or tap.
  • interval every few seconds.
  • scroll with speed.
  • load once.
strengthdata-dio-strengthnumber0 to 21How many slabs break and how far they jump and turn; 0 keeps them in place.
splitdata-dio-splitnumber0 to 40 px6How far the red and cyan layers part in depth and sideways; 0 for none.
slicesdata-dio-slicesnumber1 to 165About how many slabs each line of text breaks into.
intervaldata-dio-intervalnumber0.5 to 10 s3Average time between bursts with trigger interval, varied by the seed.
durationdata-dio-durationnumber0.1 to 2 s0.7Length of one burst; from 0.4 s it hits twice with the signal lost between.
seeddata-dio-seednumber1 to 1001Which glitch plays: the same seed gives the same one.

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, presence and size . Draws only while something on it moves, then stops. Only during a burst, and with trigger scroll while the page scrolls fast; none at rest. A timer waits between interval bursts without drawing. 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. Sudden flicker can trouble people sensitive to motion and flashing. With motion on, the text dims at most 3 times in any second, under the WCAG flash threshold.

Runs on every device. hover plays a burst on tap and on keyboard focus. The other triggers work the same as with a mouse.

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

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

Cost and quality

Download
9.1 KB min+gzip the first time a page uses it
GPU
One instanced draw of a quad per layer of a slab, one texture read per pixel; a block adds 14 layers to its slab, the hologram 7.
Memory
A canvas of the text at twice its CSS size with mip levels, 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 is rastered at 1 device pixel per CSS pixel instead of 2.

Recipes

A lineup whose names glitch under the pointer

On a festival, music or gaming site, each act or title glitches as the pointer enters its card, and stays calm the rest of the time. The effect listens on the link the heading sits in, so the whole card triggers it, and keyboard focus does too. The slice style turns the struck slabs into solid blocks that jump out of the page. Give each card its own seed so no two break alike.

Live preview needs WebGPU or WebGL 2. Three festival lineup cards on black whose act names break into 3D blocks when a card is hovered.

This example failed to draw.

<ul class="tg-lineup">
<li>
<a href="/night-strings">
<img
src="/media/festival/cello.webp"
width="960"
height="1200"
/>
<h3
data-dio="text-glitch"
data-dio-style="slice"
>Night Strings</h3>
<span>Fri 23:00</span>
</a>
</li>
<li>
<a href="/brass-signal">
<img
src="/media/festival/flugelhorn.webp"
width="960"
height="1200"
/>
<h3
data-dio="text-glitch"
data-dio-style="slice"
data-dio-seed="2"
>Brass Signal</h3>
<span>Sat 21:30</span>
</a>
</li>
<li>
<a href="/orbit-sessions">
<img
src="/media/festival/milky-way.webp"
width="1400"
height="933"
/>
<h3
data-dio="text-glitch"
data-dio-style="slice"
data-dio-seed="3"
>Orbit Sessions</h3>
<span>Sun 00:15</span>
</a>
</li>
</ul>

A hologram title as it first shows

The vhs style leans the line back with a stack of scanline copies trailing behind it, like a hologram losing its signal, and bends it like worn tape. With trigger="load" it plays once, when half of the heading is in view.

<h2
data-dio="text-glitch"
data-dio-style="vhs"
data-dio-trigger="load"
>Transmission 1994</h2>

A headline that breaks up with scroll speed

With trigger="scroll" the glitch follows the scroll speed: a slow read leaves the heading alone, a fast flick tears it apart for a moment.

<h1
data-dio="text-glitch"
data-dio-trigger="scroll"
data-dio-strength="1.5"
>Faster, louder</h1>

Notes

The glitch is drawn in 3D through the page camera: slabs move towards and away from the viewer, so a heading far from the middle of the screen shows more parallax than one in the center. Between bursts the element is plain DOM text, selectable and read by screen readers as written.

Keep bursts short and rare on pages people read: three flashes or more per second can trigger seizures, so duration stays under a second and interval above two seconds. Under reduced motion the effect does not run at all.

The canvas cannot draw background-clip: text, text-shadow, -webkit-text-stroke or vertical writing modes the way the browser does; such text stays as it is, with a warning in development.

style and trigger rebuild the effect; strength, split, slices, interval, duration and seed change live.