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

polaroids

Galleries and viewersAlso inPhoto

@dioramajs/media/polaroidsSource

Photos scattered like prints on a table: drag one to the top, click it to hold it up large.

View as Markdown
On this page
A grassy headland over the sea Small rocky islets in a calm bay A pebble shore at low tide Surf breaking on dark rocks Round boulders on a beach

Live preview needs WebGPU or WebGL 2. Five photos from the coast scattered like prints on a table; drag one to the top or click it to hold it up large.

This example failed to draw.

Drag a print to bring it to the top, click it to hold it up, or focus the stack and use the arrow keys and Enter.
Params of polaroids
style

scatter spreads the prints over the box.

Usage

Put it on a container of images: a trip, an event, a studio. start() registers polaroids, 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 polaroids
<section
class="pl-trip"
data-dio="polaroids"
tabindex="0"
aria-label="Photos from the coast. Arrow keys bring the next one to the top, Enter holds it up."
>
<img
src="/media/coast/headland-800.avif"
width="800"
height="533"
/>
<img
src="/media/coast/islets-600.avif"
width="600"
height="400"
/>
<img
src="/media/coast/shore-800.avif"
width="800"
height="533"
/>
<img
src="/media/coast/surf-800.avif"
width="800"
height="533"
/>
<img
src="/media/coast/boulders-600.avif"
width="600"
height="400"
/>
</section>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.pl-trip', 'polaroids', {
style: 'scatter',
index: 0,
open: -1,
rotate: 8,
spread: 1,
border: 10,
paper: '#fbfaf6',
shadow: 0.45,
zoom: 2,
duration: 0.5,
drag: true,
seed: 1,
})
import { start } from '@dioramajs/diorama'
import polaroids from '@dioramajs/media/polaroids'
const app = start()
app.attach('.pl-trip', polaroids({
style: 'scatter',
index: 0,
open: -1,
rotate: 8,
spread: 1,
border: 10,
paper: '#fbfaf6',
shadow: 0.45,
zoom: 2,
duration: 0.5,
drag: true,
seed: 1,
}))

Events

It dispatches these on its element; they bubble.

  • dio:index, detail: { index: number }. A print came on top; index is its place among the images, from 0. Bubbles.
  • dio:open, detail: { index: number }. A print was held up, or put back with index -1. Bubbles.

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.

ParamTypeDefaultDescription
indexdata-dio-indexnumber0 to 100Print on top, from 0.
opendata-dio-opennumber-1 to 10-1Print held up in the middle, from 0; -1 for none.
stylerebuildsdata-dio-style'scatter' | 'grid' | 'pile''scatter'
  • scatter spreads the prints over the box.
  • grid lays each over its image as the page places it, like a pinboard.
  • pile heaps them near the middle.
rotatedata-dio-rotatenumber0 to 30°8Largest angle of a print; 0 lays them straight.
spreaddata-dio-spreadnumber0 to 11How far the prints stray from their places, 0 for none.
borderdata-dio-bordernumber0 to 40 px10Width of the paper border; the bottom one is 3.4 times wider. 0 for bare photos with the images’ own corners.
paperdata-dio-papercolor'#fbfaf6'Color of the paper border.
shadowdata-dio-shadownumber0 to 10.45Darkness of the shadow under each print, 0 for none.
zoomdata-dio-zoomnumber0 to 42Largest size of a print held up, in its own sizes, never past nine tenths of the box; 0 never holds one up.
durationdata-dio-durationnumber0.1 to 2 s0.5Length of a print’s move.
dragdata-dio-dragbooleantrueA drag carries a print.
seeddata-dio-seednumber1 to 1001Arrangement of the table; a new value lays it out again.
itemsrebuildsdata-dio-itemsstring'img'Selector of the images inside the container.

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 a print moves, is carried or is held up; none at rest. 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. Prints move at once: no easing when one is raised, held up or put back. Carrying a print still follows the pointer.

Runs on every device. A tap brings a print to the top or holds it up. Carrying one needs touch-action: none on the container, so the page keeps scrolling otherwise.

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

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

Cost and quality

Download
6.6 KB min+gzip the first time a page uses it
GPU
A quad per print, up to 40, with a shadow, one texture read per pixel.
Memory
Every picture on the table.
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 trip on the table

For a travel story, an event recap or a studio’s “about us” page, the photos lie scattered at seeded angles. The visitor drags one to the top or clicks it to hold it up large. With tabindex and an aria-label the stack is reachable from the keyboard too.

<section
class="trip"
data-dio="polaroids"
tabindex="0"
aria-label="Photos from the coast. Arrow keys bring the next one to the top, Enter holds it up."
>
<img src="/trip/1.avif" />
<img src="/trip/2.avif" />
<img src="/trip/3.avif" />
</section>

A pinboard of linked projects

style="grid" keeps each print over its own place in the layout, slightly turned, like a pinboard; links inside the prints stay links.

<ul
class="board"
data-dio="polaroids"
data-dio-style="grid"
data-dio-rotate="4"
>
<li>
<a href="/work/kiln">
<img src="/work/kiln.avif" />
</a>
</li>
<li>
<a href="/work/loom">
<img src="/work/loom.avif" />
</a>
</li>
</ul>

Notes

The pictures stay plain <img> elements with their alt text, so the stack reads as a list of photos without the effect. Under reduced motion the prints move at once, without easing; a print you carry still follows the pointer.

style rebuilds the effect; the other params change live.