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

vinyl

3D and productAlso inSoundPhoto

@dioramajs/model/vinylSource

An album cover becomes a record sleeve: the disc slides out and spins.

View as Markdown
On this page
Tidelines, the debut album by Harbor Lights

Live preview needs WebGPU or WebGL 2. An album cover of a sunset over the sea; under the pointer a black record slides out of it to the right and spins, its label showing the middle of the cover.

This example failed to draw.

Move the pointer over the cover, or focus it and press Enter to keep the record out. Try the styles and the triggers.
Params of vinyl
style

trigger

Usage

Put it on img: the cover, the front of the sleeve. Without WebGL, or with reduced motion and a still record, the plain cover shows. start() registers vinyl, 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 vinyl
<img
class="sleeve"
src="/media/records/vinyl-cover.webp"
width="800"
height="800"
data-dio="vinyl"
tabindex="0"
/>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.sleeve', 'vinyl', {
style: 'black',
trigger: 'hover',
out: 0.55,
rpm: 33,
tilt: 6.9,
shadow: 0.5,
})
import { start } from '@dioramajs/diorama'
import vinyl from '@dioramajs/model/vinyl'
const app = start()
app.attach('.sleeve', vinyl({
style: 'black',
trigger: 'hover',
out: 0.55,
rpm: 33,
tilt: 6.9,
shadow: 0.5,
}))

Page transitions

Leaves by dithering its pixels away while shrinking to 96%, and its shadow fades with it. 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'black' | 'color' | 'picture' | 'cd''black'Kind of disc. black: classic black vinyl with grooves; color: colored vinyl in color; picture: a picture disc printed with the label image or the cover; cd: a silver compact disc with the rainbow of its tracks.
triggerrebuildsdata-dio-trigger'hover' | 'view' | 'play''hover'What brings the record out. hover: the pointer or keyboard focus, and a click or Enter keeps it out; view: it slides out once the sleeve is well in view and stays; play: it comes out and spins while the player named by for plays, and a click or Enter plays or pauses it.
forrebuildsdata-dio-forstring''CSS selector of the <audio> or <video> for trigger play; empty takes the closest one before the image in its parent, else the first one in the parent.
labelrebuildsdata-dio-labelstring''Center label image URL or color; empty shows the middle of the cover. With style picture, the image printed on the disc.
colordata-dio-colorcolor'#c8323c'Color of the vinyl with style color.
outdata-dio-outnumber0 to 10.55How far the record comes out, as a share of its diameter: 0 keeps it in the sleeve, 1 takes it all the way out.
rpmdata-dio-rpmnumber0 to 7833Turntable speed while it spins, in turns a minute: 33, 45 or 78. 0 keeps it still.
tiltdata-dio-tiltnumber0 to 25°6.9How far it leans toward the pointer: 0 turns the lean off.
shadowdata-dio-shadownumber0 to 10.5Density of the shadow on the page.

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, presence, reducedMotion and width . Draws at a steady rate while it is on screen and stops when it leaves. Only while the record slides, spins up or down, and spins; none at rest, and pointer moves elsewhere draw nothing. With trigger play, none while the player is paused. 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. The record comes out and goes back at once and never spins; the triggers work as usual.

Runs on every device. Nothing hovers. A tap brings the record out and back with trigger hover, plays and pauses with trigger play, unless the image sits in a link or a button.

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

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

Cost and quality

Download
5.2 KB min+gzip the first time a page uses it
GPU
Two thin discs and a sleeve, a few hundred triangles; the grooves are drawn, not modelled.
Memory
The cover image, and the label image when given.
Frames
Draws while on screen

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 record that spins while its track plays

trigger="play" links the record to a player on the page: it comes out and spins while the player plays, and goes back when it pauses. A click or Enter on the cover plays and pauses it. Name the player with for, or put it next to the image. The player keeps its own controls, so the page works without the effect.

Tidelines cover: play the preview

Kite Frequency a 20 s preview

Live preview needs WebGPU or WebGL 2. A dark release card: the cover on the left, a track title and an audio player on the right; while the track plays a record with a mustard label spins out of the cover.

This example failed to draw.

Params of vinyl
<figure class="release">
<img
src="/media/records/vinyl-cover.webp"
width="800"
height="800"
data-dio="vinyl"
data-dio-trigger="play"
data-dio-for="#preview"
data-dio-label="/media/records/vinyl-label.webp"
tabindex="0"
/>
<figcaption>
<p>Kite Frequency <span>a 20 s preview</span></p>
<audio
id="preview"
src="/media/audio/kite-frequency.mp3"
controls
preload="metadata"
>
<track
kind="captions"
src="/media/audio/kite-frequency.vtt"
srclang="en"
label="English"
/>
</audio>
</figcaption>
</figure>

Colored vinyl and a CD

style="color" presses the record in color, for a limited edition; style="picture" prints the cover or the label image over the whole disc; style="cd" shows a silver compact disc with the rainbow of its tracks. label takes the center label as an image or a color.

Tidelines on red vinyl Tidelines on CD

Live preview needs WebGPU or WebGL 2. Two copies of the same cover: from the first a red record with a mustard label slides out, from the second a silver CD.

This example failed to draw.

Params of vinyl
<div class="editions">
<img
src="/media/records/vinyl-cover.webp"
width="800"
height="800"
data-dio="vinyl"
data-dio-style="color"
data-dio-color="#c8323c"
data-dio-label="/media/records/vinyl-label.webp"
/>
<img
src="/media/records/vinyl-cover.webp"
width="800"
height="800"
data-dio="vinyl"
data-dio-style="cd"
/>
</div>

A record that comes out in view

trigger="view" slides the record out once the cover is well inside the viewport, and it stays out, spinning while it is in view. It suits a release page with one big cover.

<img
src="/releases/tidelines.webp"
width="800"
height="800"
data-dio="vinyl"
data-dio-trigger="view"
/>

Notes

At rest the sleeve is drawn exactly where the cover is, so nothing jumps when the engine takes over. The record comes out to the right by out of its diameter: leave room for it there, or it covers what sits next to the cover.

A record that only spins draws 30 frames a second; while it slides it draws at the full rate, and at rest nothing. Under reduced motion it comes out and goes back at once and never spins.

style, trigger, for and label rebuild the effect; color, out, rpm, tilt and shadow change live.