glitch
A digital glitch in short bursts: blocks slide sideways, color channels split, scanlines flicker.
-
T-minus Single, out now
-
The Eagle Has Landed EP, 14 March
-
We've Had a Problem Album, 2 May
Live preview needs WebGPU or WebGL 2. A row of three new releases of a record label, each cover breaking up in a short digital glitch every couple of seconds.
This example failed to draw.
Usage
Put it on img, video. start() registers 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.
npx @dioramajs/diorama add glitch<ul class="gl-releases"> <li> <img src="/media/festival/notes-01.webp" width="480" height="480" data-dio="glitch" data-dio-trigger="interval" data-dio-interval="2" /> <p>T-minus <span>Single, out now</span></p> </li> <li> <img src="/media/festival/notes-02.webp" width="480" height="480" data-dio="glitch" data-dio-trigger="interval" data-dio-interval="2" data-dio-seed="2" /> <p>The Eagle Has Landed <span>EP, 14 March</span></p> </li> <li> <img src="/media/festival/notes-03.webp" width="480" height="480" data-dio="glitch" data-dio-trigger="interval" data-dio-interval="2" data-dio-seed="3" /> <p>We've Had a Problem <span>Album, 2 May</span></p> </li></ul>import { start } from '@dioramajs/diorama'
const app = start()app.attach('img', 'glitch', { style: 'rgb', trigger: 'interval', strength: 1, blocks: 12, split: 8, interval: 2, duration: 0.45, seed: 1,})import { start } from '@dioramajs/diorama'import glitch from '@dioramajs/media/glitch'
const app = start()app.attach('img', glitch({ style: 'rgb', trigger: 'interval', strength: 1, blocks: 12, split: 8, interval: 2, duration: 0.45, seed: 1,}))Page transitions
Leaving a page breaks the copy up and drops it block by block; entering brings it back. 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 | 'rgb' | 'slice' | 'vhs' | 'rgb' |
|
triggerrebuildsdata-dio-trigger | 'hover' | 'interval' | 'scroll' | 'load' | 'hover' |
|
strengthdata-dio-strength | number0 to 2 | 1 | How many blocks break and how far they jump; 0 keeps only split and lines. |
blocksdata-dio-blocks | number2 to 40 | 12 | About how many bands the picture breaks into. |
splitdata-dio-split | number0 to 40 px | 8 | How far red and blue part, at the peak of a burst. |
intervaldata-dio-interval | number0.5 to 10 s | 3 | Average time between bursts with trigger interval, varied by the seed. |
durationdata-dio-duration | number0.1 to 2 s | 0.45 | Length of one burst. |
seeddata-dio-seed | number1 to 100 | 1 | Which 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 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. Nothing glitches: sudden flicker can trouble people sensitive to motion and flashing.
Runs on every device. hover plays a burst on tap. 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: { glitch: { reducedMotion: 'static' } } })Cost and quality
- Download
- 1.9 KB min+gzip the first time a page uses it
- GPU
- Three texture reads and a few integer hashes per pixel.
- Memory
- The shared texture of the image or video.
- Frames
- Idle at rest
It runs from the low tier up. Every tier draws it the same way. The quality plugin picks the tier for each device.
Recipes
A lineup that glitches under the pointer
On a festival, music or gaming site, each act or title gets a short burst as the pointer enters its card, and the card is calm the rest of the time. The slice style shifts whole blocks and smears a few into streaks. Give each card its own seed so no two glitch alike.
-
Night Strings Fri 23:00
-
Brass Signal Sat 21:30
-
Orbit Sessions Sun 00:15
Live preview needs WebGPU or WebGL 2. Three festival lineup cards on black: a cello, a flugelhorn and the night sky, each glitching as the pointer enters.
This example failed to draw.
<ul class="lineup"> <li> <img src="/media/festival/cello.webp" width="960" height="1200" data-dio="glitch" data-dio-style="slice" /> <p>Night Strings <span>Fri 23:00</span></p> </li> <li> <img src="/media/festival/flugelhorn.webp" width="960" height="1200" data-dio="glitch" data-dio-style="slice" data-dio-seed="2" /> <p>Brass Signal <span>Sat 21:30</span></p> </li> <li> <img src="/media/festival/milky-way.webp" width="1400" height="933" data-dio="glitch" data-dio-style="slice" data-dio-seed="3" /> <p>Orbit Sessions <span>Sun 00:15</span></p> </li></ul>A product film on worn tape
The effect runs on a playing <video> as well as on an image. The vhs style wobbles the frame, washes out the color and rolls a band of bad tracking down the picture. With trigger="interval" the burst comes back every few seconds, at slightly uneven times, while the video is on screen.
Live preview needs WebGPU or WebGL 2. A short film of a mustard lounge chair in a sunlit room, breaking up like a worn VHS tape every few seconds.
This example failed to draw.
<video class="tape" poster="/media/film/lounge.webp" width="1280" height="720" autoplay muted loop playsinline aria-label="Product film, 12 seconds, no sound: a lounge chair in mustard velvet in a sunlit room" data-dio="glitch" data-dio-style="vhs" data-dio-trigger="interval" data-dio-interval="2.5" data-dio-duration="0.9"> <source src="/media/film/lounge.webm" type="video/webm" /> <source src="/media/film/lounge.mp4" type="video/mp4" /></video>A hero that breaks up with scroll speed
With trigger="scroll" the glitch follows the scroll speed: a slow read leaves the image alone, a fast flick tears it apart for a moment. It suits a streetwear drop or a launch page where the hero should feel loud.
<img src="/drop/hero.avif" data-dio="glitch" data-dio-trigger="scroll" data-dio-style="slice" data-dio-strength="1.5"/>Notes
The glitch changes how the image looks for a fraction of a second; its alt stays the same. 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 unless the glitch is small.
Under reduced motion the effect does not run at all and the image shows as it is.
style and trigger rebuild the effect; strength, blocks, split, interval, duration and seed change live.