polaroids
Photos scattered like prints on a table: drag one to the top, click it to hold it up large.
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.
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.
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.
| Param | Type | Default | Description |
|---|---|---|---|
indexdata-dio-index | number0 to 10 | 0 | Print on top, from 0. |
opendata-dio-open | number-1 to 10 | -1 | Print held up in the middle, from 0; -1 for none. |
stylerebuildsdata-dio-style | 'scatter' | 'grid' | 'pile' | 'scatter' |
|
rotatedata-dio-rotate | number0 to 30° | 8 | Largest angle of a print; 0 lays them straight. |
spreaddata-dio-spread | number0 to 1 | 1 | How far the prints stray from their places, 0 for none. |
borderdata-dio-border | number0 to 40 px | 10 | Width of the paper border; the bottom one is 3.4 times wider. 0 for bare photos with the images’ own corners. |
paperdata-dio-paper | color | '#fbfaf6' | Color of the paper border. |
shadowdata-dio-shadow | number0 to 1 | 0.45 | Darkness of the shadow under each print, 0 for none. |
zoomdata-dio-zoom | number0 to 4 | 2 | Largest size of a print held up, in its own sizes, never past nine tenths of the box; 0 never holds one up. |
durationdata-dio-duration | number0.1 to 2 s | 0.5 | Length of a print’s move. |
dragdata-dio-drag | boolean | true | A drag carries a print. |
seeddata-dio-seed | number1 to 100 | 1 | Arrangement of the table; a new value lays it out again. |
itemsrebuildsdata-dio-items | string | '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.