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

reveal

PhotoAlso inVideoScroll scenes

@dioramajs/media/revealSource

The image wipes in with a soft noisy edge as it scrolls into view, or fades, opens in bands or from the center.

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

Live preview needs WebGPU or WebGL 2. A photo of misty ridges that wipes in with a soft, uneven edge.

This example failed to draw.

When enough of the image has entered the viewport, it is uncovered from one side by a soft edge with an uneven, inky rim, while the picture settles from a slight zoom. Once revealed it is the image as it is, pixel for pixel. Images that were already on screen when the page loaded stay as they are: nothing the visitor has seen disappears to play an intro. Other styles fade it in with a short drift, open it in bands one after another, or open a circle from the center.

Every switch and slider plays the reveal again.

Params of reveal
style

wipe uncovers it with an uneven edge.

trigger

view plays when the image enters.

direction

Usage

Put it on img, video. start() registers reveal, 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 reveal
<img
class="ridges"
src="/media/ridges.jpg"
width="1800"
height="1200"
data-dio="reveal"
/>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.ridges', 'reveal', {
style: 'wipe',
trigger: 'view',
direction: 'up',
duration: 1.2,
delay: 0,
threshold: 0.2,
zoom: 1.12,
softness: 0.12,
})
import { start } from '@dioramajs/diorama'
import reveal from '@dioramajs/media/reveal'
const app = start()
app.attach('.ridges', reveal({
style: 'wipe',
trigger: 'view',
direction: 'up',
duration: 1.2,
delay: 0,
threshold: 0.2,
zoom: 1.12,
softness: 0.12,
}))

Page transitions

Leaving a page closes the wipe again, entering opens it. A flight target lands on the revealed 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'wipe' | 'fade' | 'blinds' | 'iris''wipe'
  • wipe uncovers it with an uneven edge.
  • fade fades it in, drifting 40 px along the direction.
  • blinds opens it in bands one after another.
  • iris opens a circle from the center, for a centered subject.
triggerrebuildsdata-dio-trigger'view' | 'scroll''view'
  • view plays when the image enters.
  • scroll ties it to the scroll position, both ways.
directionrebuildsdata-dio-direction'up' | 'down' | 'left' | 'right''up'Where the wipe travels: up uncovers from the bottom. The fade drifts the same way; the iris ignores it.
durationdata-dio-durationnumber0.2 to 3 s1.2Length of the reveal.
delaydata-dio-delaynumber0 to 2 s0Wait after the trigger, for a cascade across a grid.
thresholddata-dio-thresholdnumber0 to 10.2Share of the image height that must be in view, above the bottom tenth of the viewport, before it plays.
zoomdata-dio-zoomnumber0 to 1.51.12Scale the picture settles from; 1 or 0 for none.
softnessdata-dio-softnessnumber0 to 0.50.12Width of the soft edge as a share of the image; uneven in wipe and iris, plain in blinds.
seedrebuildsdata-dio-seednumber1 to 1001Shape of the uneven edge.

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 while revealing, and with trigger scroll 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 same as with a mouse: it follows the scroll.

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

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

Cost and quality

Download
1.4 KB min+gzip the first time a page uses it
GPU
One texture read of the image and one of a small noise tile per pixel.
Memory
The shared texture of the image and a shared 64 x 64 noise tile.
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

Cascade across a grid

Give each image a slightly longer delay than the one before it. The row enters together, so the prints open one after another from left to right.

Dawn over the ridge Dusk over the paper hills Paper lanterns rising over the hills at night

Live preview needs WebGPU or WebGL 2. Three prints that wipe in one after another.

This example failed to draw.

Each print waits 0.15 s longer than the one before it.

<div class="prints">
<img
src="/media/prints/dawn.jpg"
width="1000"
height="1000"
data-dio="reveal"
/>
<img
src="/media/prints/dusk.jpg"
width="1000"
height="1250"
data-dio="reveal"
data-dio-delay="0.15"
/>
<img
src="/media/prints/lanterns.jpg"
width="1000"
height="1250"
data-dio="reveal"
data-dio-delay="0.3"
/>
</div>

Scrub it with the scroll

With data-dio-trigger="scroll" the reveal follows the scroll position both ways: the image opens as it rises to the middle of the viewport and closes again when you scroll back. Use it for a wide image that a reader passes slowly, such as a panorama between two sections.

<img
src="/media/ridges.jpg"
data-dio="reveal"
data-dio-trigger="scroll"
data-dio-direction="right"
/>

A quiet fade for long reads

The fade style drops the edge and drifts the image 40 px into place. Set zoom to 1 as well and an article’s figures arrive without drawing attention away from the text.

<img
src="/media/prints/night.jpg"
data-dio="reveal"
data-dio-style="fade"
data-dio-zoom="1"
data-dio-duration="0.8"
/>

Bands across a wide banner

The blinds style opens the image in bands, each half a reveal after the one before it. A low softness keeps the bands crisp, which suits a banner of flat shapes or type.

<img
src="/media/ridges.jpg"
data-dio="reveal"
data-dio-style="blinds"
data-dio-direction="down"
data-dio-softness="0.02"
/>

Notes

An image that is already in view when the page opens stays as it is: the reveal plays only for images the reader scrolls to, so nothing on the first screen disappears to play an intro. The example on this page plays again after each change for the same reason.

The reveal starts when threshold of the image height is in view above the bottom tenth of the viewport. An image that only peeks in at the bottom edge has not been looked at yet, so it waits.

style, trigger, direction and seed rebuild the effect when they change. Set them in the markup rather than switching them while the image is on screen.