# vinyl

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

At rest the sleeve lies exactly where the cover image was, with a soft shadow under it. On hover, once in view or while its player plays, a record slides out of the sleeve to the right and spins at 33 rpm, its grooves catching a sheen of light that stays put while the disc turns. The center label carries the cover or a picture of its own. The sleeve leans a little toward the pointer.

Module `model`, category 3D and product. Import `@dioramajs/model/vinyl`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/model/src/vinyl.ts)

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.

```html title="index.html"
<img class="sleeve" src="/media/records/vinyl-cover.webp" alt="Tidelines, the debut album by Harbor Lights" width="800" height="800" data-dio="vinyl" tabindex="0" />
```

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

```html
<img src="/releases/tidelines.webp" alt="Tidelines, the debut album by Harbor Lights" width="600" height="600" data-dio="vinyl" tabindex="0" />
```

In page transitions: Leaves by dithering its pixels away while shrinking to 96%, and its shadow fades with it.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-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. |
| `trigger` (rebuilds) | `data-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. |
| `for` (rebuilds) | `data-dio-for` | `string` | `''` | 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. |
| `label` (rebuilds) | `data-dio-label` | `string` | `''` | Center label image URL or color; empty shows the middle of the cover. With style picture, the image printed on the disc. |
| `color` | `data-dio-color` | `color` | `'#c8323c'` | Color of the vinyl with style color. |
| `out` | `data-dio-out` | `number` 0 to 1 | `0.55` | How far the record comes out, as a share of its diameter: 0 keeps it in the sleeve, 1 takes it all the way out. |
| `rpm` | `data-dio-rpm` | `number` 0 to 78 | `33` | Turntable speed while it spins, in turns a minute: 33, 45 or 78. 0 keeps it still. |
| `tilt` | `data-dio-tilt` | `number` 0 to 25° | `6.9` | How far it leans toward the pointer: 0 turns the lean off. |
| `shadow` | `data-dio-shadow` | `number` 0 to 1 | `0.5` | Density of the shadow on the page. |

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

### Variants

- `style`: `black`, `color`, `picture`, `cd`
- `trigger`: `hover`, `view`, `play`

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`opacity`](/docs/api/inputs#opacity), [`presence`](/docs/api/inputs#presence), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`width`](/docs/api/inputs#input-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. 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. 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.

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

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

## Cost and quality

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

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

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

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.

```html title="index.html"
<figure class="release">
  <img src="/media/records/vinyl-cover.webp" alt="Tidelines cover: play the preview" 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.

Two copies of the same cover: from the first a red record with a mustard label slides out, from the second a silver CD.

```html title="index.html"
<div class="editions">
  <img src="/media/records/vinyl-cover.webp" alt="Tidelines on red vinyl" 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" alt="Tidelines on CD" 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.

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

## Related

- [book](/docs/effects/book.md): A cover image made a 3D book that turns to show its spine and opens on hover.
- [box](/docs/effects/box.md): A product box built from pictures of its faces: turn it, tilt it, open its lid.
- [coin](/docs/effects/coin.md): A coin, medal or token struck from a logo or a photo: it turns, catches the light and flips over.
- [device](/docs/effects/device.md): A screenshot or a video shown in a 3D phone, tablet, laptop or browser window.
- [explode](/docs/effects/explode.md): An exploded view of a model: its parts move apart as the section scrolls.
- [hotspots](/docs/effects/hotspots.md): Feature callouts pinned to points of a model, real buttons that follow it as it turns.
- [label](/docs/effects/label.md): A flat label wrapped around a can, a bottle or a jar that turns to show all of it.
- [model](/docs/effects/model.md): A glTF model fitted into the element, lit, turnable and recolored from markup.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
