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

image

Photo

@dioramajs/media/imageSource

Draws the image or video unchanged, as a GL copy that page flights and other effects build on.

View as Markdown
On this page
A brass astrolabe of 1462, its star map cut in fine tracery

Live preview needs WebGPU or WebGL 2. A photo of a brass astrolabe whose frame switches between full, card, round and contained, with the drawn copy following each change.

This example failed to draw.

The copy is the image as the page draws it. Switch the frame and the copy crops, rounds and letterboxes with the CSS.
Frame

Each frame is plain CSS on the image: size, border-radius, object-fit.

Usage

Put it on img, video. start() registers image, so the attribute alone puts it on an element. The tabs below are the example above, with the values you set.

<img
class="astrolabe"
src="/media/portfolio/astrolabe.webp"
width="1400"
height="933"
data-dio="image"
/>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.astrolabe', 'image')
import { start } from '@dioramajs/diorama'
import image from '@dioramajs/media/image'
const app = start()
app.attach('.astrolabe', image())

Page transitions

Fades with the page transition. How a flight flies.

Params

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

It has no params.

Inputs and frames

Draws only when you scroll, move the pointer over it or change a param. Only when the layout or the picture changes; none at rest. A playing video draws its frames. 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. Unchanged, it does not move.

Runs on every device. The same as with a mouse.

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

import { start } from '@dioramajs/diorama'
start({ effects: { image: { reducedMotion: 'off' } } })

Cost and quality

Download
0.2 KB min+gzip the first time a page uses it
GPU
One textured quad.
Memory
One texture the size of the decoded picture.
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

Fly a thumbnail to its page

Give the thumbnail on the list page and the cover on the project page the same data-dio-key. The thumbnail needs a drawn copy to fly, and image gives it one without changing how it looks. The cover may carry another effect, such as ripple, and the copy lands into it.

work.html
<a href="/work/astrolabe">
<img
src="/img/astrolabe-thumb.avif"
data-dio="image"
data-dio-key="astrolabe"
/>
</a>
work/astrolabe.html
<img
src="/img/astrolabe.avif"
data-dio="image ripple"
data-dio-key="astrolabe"
/>

Let every keyed image fly

On a site with many keyed images, attach image once from code instead of writing it on each one. The selector skips elements that already carry an effect, since their copy flies anyway.

import { start } from '@dioramajs/diorama'
const app = start()
app.attach(
'img[data-dio-key]:not([data-dio]), video[data-dio-key]:not([data-dio])',
'image',
)

A product film that flies with the page

A playing <video> draws each new frame and nothing while it is paused, so a muted loop on a shop card costs a texture upload per frame and no more. With a key it flies to the product page like an image.

<video
src="/film/lounge.webm"
poster="/film/lounge.webp"
muted
loop
autoplay
playsinline
data-dio="image"
data-dio-key="lounge"
></video>

Hundreds of tiles that never move

Each drawn frame measures every visible layer. For a large grid of images that move only with the scroll, data-dio-track="layout" caches the position at layout changes and subtracts the scroll instead.

<img
src="/tiles/017.avif"
data-dio="image"
data-dio-track="layout"
/>

Notes

The canvas covers the viewport above the page, so a copy draws over any HTML laid on top of its image. Give a caption or button over a drawn image position: relative and a z-index of 2 or more to keep it in front.

The copy reads object-fit, object-position and border-radius again when the element’s box changes, not in every frame: a style that changes while the box stays the same shows on the copy at its next resize. none and scale-down draw as contain, and corners of different radii draw with the largest one; development builds warn about both.