pixelate
The image resolves from big pixels to sharp as it scrolls into view, or breaks into pixels on hover.
Live preview needs WebGPU or WebGL 2. A photo of a brass astrolabe that resolves from large square pixels to the sharp image.
This example failed to draw.
Every switch and slider plays the reveal again.
Usage
Put it on img, video. start() registers pixelate, 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 pixelate<img class="astrolabe" src="/media/portfolio/astrolabe.webp" width="1400" height="933" data-dio="pixelate"/>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.astrolabe', 'pixelate', { style: 'square', motion: 'steps', trigger: 'view', cell: 32, duration: 1.2, delay: 0,})import { start } from '@dioramajs/diorama'import pixelate from '@dioramajs/media/pixelate'
const app = start()app.attach('.astrolabe', pixelate({ style: 'square', motion: 'steps', trigger: 'view', cell: 32, duration: 1.2, delay: 0,}))Page transitions
Leaving a page breaks the copy into blocks and fades it, entering resolves it. A flight lands on the sharp image. 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 | 'square' | 'round' | 'hex' | 'square' |
|
triggerrebuildsdata-dio-trigger | 'view' | 'hover' | 'scroll' | 'view' |
|
motionrebuildsdata-dio-motion | 'steps' | 'smooth' | 'steps' |
|
celldata-dio-cell | number4 to 128 px | 32 | Side of the biggest blocks, where the reveal starts and hover ends. |
durationdata-dio-duration | number0.2 to 4 s | 1.2 | Length of the reveal, or of the change on hover. |
delaydata-dio-delay | number0 to 2 s | 0 | Wait after the image comes into view, for a cascade across a grid. |
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, reducedMotion and size
. Draws only while something on it moves, then stops. Only while the blocks change: during the reveal and the hover change, and with trigger scroll while scrolling. 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. With view and scroll the image is shown as it is, without blocks. With hover the blocks fade in at full size in 0.15 s instead of growing.
Runs on every device. view and scroll work the same as with a mouse; with hover the image stays sharp.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { pixelate: { reducedMotion: 'off' } } })Cost and quality
- Download
- 1.6 KB min+gzip the first time a page uses it
- GPU
- Four texture reads per pixel while blocks show, one on the low tier.
- Memory
- The shared texture of the image or video.
- 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 | Each block takes the color at its center instead of the average of four reads. |
Recipes
Pieces that turn to pixels under the pointer
With trigger="hover" the image is sharp and breaks into blocks while the pointer is over it, which suits a retro or gaming portfolio and a gallery of digital art. A small cell and a short duration keep it playful rather than hiding the work.
Live preview needs WebGPU or WebGL 2. Three artworks on black, a cyanotype, a tea bowl and an aurora, each breaking into pixels under the pointer.
This example failed to draw.
<ul class="pieces"> <li> <img src="/media/work/cyanotype.webp" width="480" height="384" data-dio="pixelate" data-dio-trigger="hover" data-dio-cell="16" data-dio-duration="0.45" /> </li> <li> <img src="/media/work/hares-fur.webp" width="480" height="384" data-dio="pixelate" data-dio-trigger="hover" data-dio-cell="16" data-dio-duration="0.45" /> </li> <li> <img src="/media/work/polar-night.webp" width="480" height="384" data-dio="pixelate" data-dio-trigger="hover" data-dio-cell="16" data-dio-duration="0.45" /> </li></ul>Cascade across a grid
Give each image a slightly longer delay than the one before it, so a row resolves one tile after another as it scrolls into view.
<div class="grid"> <img src="/work/one.avif" data-dio="pixelate" /> <img src="/work/two.avif" data-dio="pixelate" data-dio-delay="0.15" /> <img src="/work/three.avif" data-dio="pixelate" data-dio-delay="0.3" /></div>Hexagons tied to the scroll
With trigger="scroll" the blocks shrink as the image rises to the middle of the viewport and grow again when the reader scrolls back. style="hex" with motion="smooth" gives a softer, honeycomb look for an art or science page.
<img src="/plates/algae.avif" data-dio="pixelate" data-dio-trigger="scroll" data-dio-style="hex" data-dio-motion="smooth"/>Notes
A reveal on the first screen plays as the page opens: the image is hidden until the effect draws its first frame, at most three seconds. An image the reader already saw as plain HTML stays sharp and never breaks up again. Under reduced motion the reveal is skipped, and hover fades the blocks in without growing them.
In round the page shows between the dots, so the look depends on the background behind the image.
List pixelate before color effects such as tone in data-dio, so they color the blocks as well.
style, trigger and motion rebuild the effect; cell, duration and delay change live.


