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

tilt

PhotoAlso inBlocks and cards

@dioramajs/media/tiltSource

A card image tilts toward the pointer in its own perspective, with glare and foil.

View as Markdown
On this page
A gift card in dark green with fine gold lines and a gold star

Live preview needs WebGPU or WebGL 2. A dark green gift card with gold lines that tilts toward the pointer, lifts and catches a glare, with gold foil on its lines when foil is raised.

This example failed to draw.

Move the pointer over the card. Raise foil to see the holographic sheen on the gold lines, which the mask allows.
Params of tilt

Usage

Put it on img, video. start() registers tilt, 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 tilt
<img
class="gift-card"
src="/media/shop/gift-card.webp"
width="1040"
height="656"
data-dio="tilt"
data-dio-mask="/media/shop/gift-foil.png"
/>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.gift-card', 'tilt', {
tilt: 12,
lift: 20,
perspective: 800,
ease: 0.12,
glare: 0.25,
foil: 0,
shadow: 0.35,
reverse: false,
gyro: false,
})
import { start } from '@dioramajs/diorama'
import tilt from '@dioramajs/media/tilt'
const app = start()
app.attach('.gift-card', tilt({
tilt: 12,
lift: 20,
perspective: 800,
ease: 0.12,
glare: 0.25,
foil: 0,
shadow: 0.35,
reverse: false,
gyro: false,
}))

Page transitions

Fades with the page transition; a flight carries the flat copy. How a flight flies.

Params

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

ParamTypeDefaultDescription
tiltdata-dio-tiltnumber0 to 45°12Largest tilt.
liftdata-dio-liftnumber0 to 100 px20Rise toward the viewer while hovered.
perspectivedata-dio-perspectivenumber200 to 3000 px800Perspective distance of the card.
easedata-dio-easenumber0 to 1 s0.12Smoothing of the tilt.
glaredata-dio-glarenumber0 to 10.25Strength of the glare.
foildata-dio-foilnumber0 to 10Strength of the holographic foil.
maskrebuildsdata-dio-maskstring''URL of the foil mask, white where the foil shows.
shadowdata-dio-shadownumber0 to 10.35Density of the shadow under the card.
reversedata-dio-reversebooleanfalseTilts away from the pointer.
gyrodata-dio-gyrobooleanfalseTilting the phone leans the card where no pointer does, against the angle the phone is held at, which it follows over a few seconds; iOS asks for permission on the first tap.

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, height, opacity, reducedMotion, size, width, x and y . Draws only while something on it moves, then stops. Only while the card tilts or settles; none at rest, and pointer moves outside the card draw nothing. 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. No tilt or lift; glare and foil still follow the pointer.

Runs on every device. The card tilts toward the finger while it is down; scrolling is never blocked. With gyro the phone tilt leans it, and glare and foil follow.

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

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

Cost and quality

Download
3.4 KB min+gzip the first time a page uses it
GPU
A 16 × 16 surface, one noise read for the foil and a shadow plane.
Memory
The image and the optional foil mask.
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

A festival pass with foil

Foil needs a mask: a grayscale image of the card, white where the foil is. Here the mask covers the title, the rings and the stripe, so the rest of the pass stays matte. The pass is a link to the tickets page, and its focus ring stays on the link in the page.

Live preview needs WebGPU or WebGL 2. A blue weekend pass whose title, rings and stripe shift through rainbow colors as it tilts.

This example failed to draw.

Params of tilt
<a class="pass" href="/docs/effects/tilt">
<img
src="/media/festival/pass.webp"
width="1080"
height="680"
data-dio="tilt"
data-dio-foil="0.7"
data-dio-mask="/media/festival/pass-foil.png"
/>
</a>

Covers in a grid

Album, book and episode covers are pictures with the text already in them, so they tilt as one piece. Lower tilt, lift and glare for a grid, where several covers sit side by side and a strong tilt would cover the neighbors.

  1. Signal Notes 01, T-minus
  2. Signal Notes 02, The Eagle Has Landed
  3. Signal Notes 03, We've Had a Problem

Live preview needs WebGPU or WebGL 2. Three square podcast covers in a row, each leaning slightly toward the pointer.

This example failed to draw.

<ol class="episodes">
<li>
<img
src="/media/festival/notes-01.webp"
width="480"
height="480"
data-dio="tilt"
data-dio-tilt="8"
data-dio-lift="12"
data-dio-glare="0.15"
/>
</li>
<li>
<img
src="/media/festival/notes-02.webp"
width="480"
height="480"
data-dio="tilt"
data-dio-tilt="8"
data-dio-lift="12"
data-dio-glare="0.15"
/>
</li>
<li>
<img
src="/media/festival/notes-03.webp"
width="480"
height="480"
data-dio="tilt"
data-dio-tilt="8"
data-dio-lift="12"
data-dio-glare="0.15"
/>
</li>
</ol>

Foil that follows the phone

A phone has no pointer to hover, so turn on gyro: tilting the phone leans the card and moves the foil. The card follows the change from the angle you hold the phone at and settles flat after a few seconds of holding still. iOS asks for permission on the first tap on the page.

<img
src="/cards/0427.png"
data-dio="tilt"
data-dio-foil="0.8"
data-dio-mask="/cards/0427-foil.png"
data-dio-gyro="true"
/>

Notes

The engine draws pictures, not HTML: a card whose title and price are HTML over the image stays flat while the image tilts under it. Render the card as one image, as tickets, covers and collectible cards already are, and keep live text next to it.

A tilted card rises above the copies of its neighbors and goes back to their level when it settles.

The link or button around the card keeps its own focus ring. On keyboard focus the card lifts without tilting.