# polaroids

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

Each image becomes a print with a white border and a wider bottom edge, lying at a small angle with a soft shadow: scattered over the box, over the places the page gives the images, or in a loose pile. A drag lifts a print, carries it on top of the others and puts it down where it is let go. A click brings a print to the top; a click on the top one holds it up in the middle, straight and larger, while the others dim, and a click anywhere or Escape puts it back. A print whose image is a link follows it instead.

Module `media`, category Galleries and viewers. Import `@dioramajs/media/polaroids`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/media/src/polaroids.ts)

Five photos from the coast scattered like prints on a table; drag one to the top or click it to hold it up large.

```html title="index.html"
<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" alt="A grassy headland over the sea" width="800" height="533" />
  <img src="/media/coast/islets-600.avif" alt="Small rocky islets in a calm bay" width="600" height="400" />
  <img src="/media/coast/shore-800.avif" alt="A pebble shore at low tide" width="800" height="533" />
  <img src="/media/coast/surf-800.avif" alt="Surf breaking on dark rocks" width="800" height="533" />
  <img src="/media/coast/boulders-600.avif" alt="Round boulders on a beach" width="600" height="400" />
</section>
```

## 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.

```html
<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" alt="The headland" /><img src="/trip/2.avif" alt="The islets" /><img src="/trip/3.avif" alt="The shore" /></section>
```

In page transitions: Fades with the page transition.

- Event `dio:index`, detail `{ index: number }`: A print came on top; index is its place among the images, from 0. Bubbles.

- Event `dio:open`, detail `{ index: number }`: A print was held up, or put back with index -1. Bubbles.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `index` | `data-dio-index` | `number` 0 to 10 | `0` | Print on top, from 0. |
| `open` | `data-dio-open` | `number` -1 to 10 | `-1` | Print held up in the middle, from 0; -1 for none. |
| `style` (rebuilds) | `data-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. |
| `rotate` | `data-dio-rotate` | `number` 0 to 30° | `8` | Largest angle of a print; 0 lays them straight. |
| `spread` | `data-dio-spread` | `number` 0 to 1 | `1` | How far the prints stray from their places, 0 for none. |
| `border` | `data-dio-border` | `number` 0 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. |
| `paper` | `data-dio-paper` | `color` | `'#fbfaf6'` | Color of the paper border. |
| `shadow` | `data-dio-shadow` | `number` 0 to 1 | `0.45` | Darkness of the shadow under each print, 0 for none. |
| `zoom` | `data-dio-zoom` | `number` 0 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. |
| `duration` | `data-dio-duration` | `number` 0.1 to 2 s | `0.5` | Length of a print’s move. |
| `drag` | `data-dio-drag` | `boolean` | `true` | A drag carries a print. |
| `seed` | `data-dio-seed` | `number` 1 to 100 | `1` | Arrangement of the table; a new value lays it out again. |
| `items` (rebuilds) | `data-dio-items` | `string` | `'img'` | Selector of the images inside the container. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `style`: `scatter`, `grid`, `pile`
  - `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.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`opacity`](/docs/api/inputs#opacity), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`size`](/docs/api/inputs#size), [`width`](/docs/api/inputs#input-width), [`x`](/docs/api/inputs#input-x), [`y`](/docs/api/inputs#input-y). Draws only while something on it moves, then stops. Only while a print moves, is carried or is held up; none at rest. See [how a frame is decided](/docs/concepts/frames).

## 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.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { polaroids: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 6.6 KB 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.

See [the quality plugin](/docs/effects/quality).

## 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.

```html
<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.

```html
<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.

## Related

- [carousel](/docs/effects/carousel.md): Pictures on a 3D ring that turns with a drag, the keys, the page scroll or by itself, the front one enlarged.
- [coverflow](/docs/effects/coverflow.md): A row of covers as the classic cover flow: the middle one faces you, its neighbours turn away in perspective.
- [flipbook](/docs/effects/flipbook.md): The page images of a container become a book whose pages bend as they turn.
- [gallery](/docs/effects/gallery.md): A container of images shows one at a time and changes them with a displacement, a slide, a crossfade or a zoom.
- [hover-preview](/docs/effects/hover-preview.md): Over a list of projects, the picture of the item under the pointer follows the pointer, stands beside the item or holds a fixed place.
- [lightbox](/docs/effects/lightbox.md): A click opens an image full screen: its copy flies out of the grid, pages and zooms.
- [stack](/docs/effects/stack.md): The images of a container become a pile of cards; a swipe, a click or a key throws the top one off.
- [ambient](/docs/effects/ambient.md): A soft glow in the colors of the frame around a video or an image, like ambient mode.
- [Reduced motion](/docs/guides/reduced-motion.md)
