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

parallax

PhotoAlso inVideoScroll scenes

@dioramajs/media/parallaxSource

The image drifts inside its frame with the pointer and the scroll; with a depth map, in 2.5D.

View as Markdown
On this page
Misty ridges at dusk, one behind another

Live preview needs WebGPU or WebGL 2. Misty ridges at dusk in 2.5D from a photo and a depth map; near ridges move more than far ones as the pointer moves and the page scrolls.

This example failed to draw.

Move the pointer over the photo, then scroll the page. The focus slider picks the depth that holds still.
Params of parallax

Usage

Put it on img, video. start() registers parallax, 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 parallax
<img
src="/media/ridges.jpg"
width="1800"
height="1200"
data-dio="parallax"
data-dio-map="/media/ridges-depth.png"
/>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('img', 'parallax', {
depth: 0.04,
scroll: 0.12,
ease: 0.12,
focus: 0.5,
})
import { start } from '@dioramajs/diorama'
import parallax from '@dioramajs/media/parallax'
const app = start()
app.attach('img', parallax({
depth: 0.04,
scroll: 0.12,
ease: 0.12,
focus: 0.5,
}))

Page transitions

Fades with the page transition. A keyed flight carries the framing it had. How a flight flies.

Params

Every param is also an attribute, and both app.attach() and the handle take it by name.

ParamTypeDefaultDescription
depthdata-dio-depthnumber0 to 0.20.04How far the pointer moves the picture, as a share of the box.
scrolldata-dio-scrollnumber0 to 0.50.12How far the picture travels while the box crosses the viewport.
easedata-dio-easenumber0 to 1 s0.12How softly the picture follows the pointer.
maprebuildsdata-dio-mapstring''URL of a depth map for the same frame, white near; empty for a flat shift.
focusdata-dio-focusnumber0 to 10.5Depth that stays put, 0 far to 1 near; nearer parts move one way, farther the other.

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, over, pointer and progress . Draws only while something on it moves, then stops. While the pointer moves over it and the motion settles, and 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 image is shown as it is, and the engine does not load for it.

Runs on every device. The pointer part is off on devices without hover, so taps do not jolt the picture; the scroll part works.

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

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

Cost and quality

Download
1.1 KB min+gzip the first time a page uses it
GPU
One texture read per pixel; with a depth map 7 to 16 reads of the map, by quality tier.
Memory
The shared texture of the image, plus the depth map. A map half the size of the image, as a grayscale PNG, is enough.
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
lowDepth search in 3 layers, refined 3 times.
mediumDepth search in 6 layers, refined 4 times.
highDepth search in 10 layers, refined 5 times.

Recipes

A depth map from the photo

map is a grayscale image of the same frame, white where things are near. The map of the ridges above comes from the photo itself, since haze makes far ridges lighter: inverted, blurred and saved at half the size, it weighs 70 KB. A depth estimation model gives one for any photo.

<img
src="/img/ridges.jpg"
data-dio="parallax"
data-dio-map="/img/ridges-depth.png"
/>

focus picks the depth that stays put. At 0.5 the middle ridges hold still while the near ones move one way and the far ones the other. At 0 the sky holds and everything in front of it moves.

Without a map

Without map the whole picture moves as one layer: it drifts away from the pointer and travels down through its frame as the page scrolls. It needs nothing but the photo.

A cliff edge above a grey sea under scattered clouds

Live preview needs WebGPU or WebGL 2. A photo of a cliff above the sea that drifts inside its frame with the pointer and the scroll.

This example failed to draw.

Params of parallax
<img
src="/media/portfolio/outer-coast.webp"
width="1600"
height="1067"
data-dio="parallax"
/>

A headline over a moving hero

The canvas draws the copy above the page, so text laid over the image needs a z-index above it. Keep depth low on a hero with text, so the picture moves under the words without pulling the eye from them.

A wave breaking over concrete steps into the sea

Sea Steps, 2026

Twelve tides on one concrete stair

Live preview needs WebGPU or WebGL 2. A hero image of a wave on sea steps that drifts behind a white headline.

This example failed to draw.

<header class="hero">
<img
src="/media/portfolio/sea-steps.webp"
width="1600"
height="1067"
data-dio="parallax"
data-dio-depth="0.025"
/>
<div class="hero-copy">
<p>Sea Steps, 2026</p>
<h2>Twelve tides on one concrete stair</h2>
</div>
</header>
.hero-copy {
position: relative;
z-index: 2;
}

Scroll only

With depth at 0 the pointer does nothing and the picture only travels with the scroll. Use it where the pointer is busy with something else, such as a card that is also a link, or to make the motion the same on touch screens and desktops.

<img
src="/img/canyon.avif"
data-dio="parallax"
data-dio-depth="0"
data-dio-scroll="0.2"
/>

Notes

The picture is drawn slightly larger than its box so the moving edge never shows, which crops a little of it. Keep faces and text away from the edges of a photo you give it.

A depth map needs no special tool: any grayscale image of the same frame works, white near and black far. A map from a depth estimation model, a render pass of a 3D scene or a hand-painted mask all do. Where the depth jumps sharply, the far side shows a stretched sliver; blur the map by a few pixels to hide it.