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

pixelate

PhotoAlso inVideoScroll scenes

@dioramajs/media/pixelateSource

The image resolves from big pixels to sharp as it scrolls into view, or breaks into pixels on hover.

View as Markdown
On this page
A brass astrolabe, its rete of star pointers over a plate engraved with the signs of the zodiac

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.

The reveal plays as the image scrolls into view. Switch the style, the trigger or the ease; each change plays it again.

Every switch and slider plays the reveal again.

Params of pixelate
style

square draws square blocks.

motion

steps halves the blocks one size at a time.

trigger

view resolves it once in view.

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.

Terminal window
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.

ParamTypeDefaultDescription
stylerebuildsdata-dio-style'square' | 'round' | 'hex''square'
  • square draws square blocks.
  • round draws dots, the page between.
  • hex draws hexagons.
triggerrebuildsdata-dio-trigger'view' | 'hover' | 'scroll''view'
  • view resolves it once in view.
  • hover pixelates under the pointer.
  • scroll scrubs it.
motionrebuildsdata-dio-motion'steps' | 'smooth''steps'
  • steps halves the blocks one size at a time.
  • smooth shrinks them continuously.
celldata-dio-cellnumber4 to 128 px32Side of the biggest blocks, where the reveal starts and hover ends.
durationdata-dio-durationnumber0.2 to 4 s1.2Length of the reveal, or of the change on hover.
delaydata-dio-delaynumber0 to 2 s0Wait 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.

TierWhat changes
lowEach 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.

  • A cyanotype of a branching alga, white on deep blue
  • A dark tea bowl with a streaked glaze
  • Green aurora over the night side of the Earth, seen from orbit

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.