# reveal

The image wipes in with a soft noisy edge as it scrolls into view, or fades, opens in bands or from the center.

When enough of the image has entered the viewport, it is uncovered from one side by a soft edge with an uneven, inky rim, while the picture settles from a slight zoom. Once revealed it is the image as it is, pixel for pixel. Images that were already on screen when the page loaded stay as they are: nothing the visitor has seen disappears to play an intro. Other styles fade it in with a short drift, open it in bands one after another, or open a circle from the center.

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

A photo of misty ridges that wipes in with a soft, uneven edge.

```html title="index.html"
<img class="ridges" src="/media/ridges.jpg" alt="Misty ridges at dusk, one behind another" width="1800" height="1200" data-dio="reveal" />
```

## Usage

Put it on: img, video.

`start()` registers `reveal`, so the attribute alone puts it on an element.

```html
<img src="/shot.avif" alt="Project shot" data-dio="reveal" />
```

In page transitions: Leaving a page closes the wipe again, entering opens it. A flight target lands on the revealed image.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'wipe' \| 'fade' \| 'blinds' \| 'iris'` | `'wipe'` | wipe uncovers it with an uneven edge; fade fades it in, drifting 40 px along the direction; blinds opens it in bands one after another; iris opens a circle from the center, for a centered subject. |
| `trigger` (rebuilds) | `data-dio-trigger` | `'view' \| 'scroll'` | `'view'` | view plays when the image enters; scroll ties it to the scroll position, both ways. |
| `direction` (rebuilds) | `data-dio-direction` | `'up' \| 'down' \| 'left' \| 'right'` | `'up'` | Where the wipe travels: up uncovers from the bottom. The fade drifts the same way; the iris ignores it. |
| `duration` | `data-dio-duration` | `number` 0.2 to 3 s | `1.2` | Length of the reveal. |
| `delay` | `data-dio-delay` | `number` 0 to 2 s | `0` | Wait after the trigger, for a cascade across a grid. |
| `threshold` | `data-dio-threshold` | `number` 0 to 1 | `0.2` | Share of the image height that must be in view, above the bottom tenth of the viewport, before it plays. |
| `zoom` | `data-dio-zoom` | `number` 0 to 1.5 | `1.12` | Scale the picture settles from; 1 or 0 for none. |
| `softness` | `data-dio-softness` | `number` 0 to 0.5 | `0.12` | Width of the soft edge as a share of the image; uneven in wipe and iris, plain in blinds. |
| `seed` (rebuilds) | `data-dio-seed` | `number` 1 to 100 | `1` | Shape of the uneven edge. |

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

### Variants

- `style`: `wipe`, `fade`, `blinds`, `iris`
  - `wipe` uncovers it with an uneven edge.
  - `fade` fades it in, drifting 40 px along the direction.
  - `blinds` opens it in bands one after another.
  - `iris` opens a circle from the center, for a centered subject.
- `trigger`: `view`, `scroll`
  - `view` plays when the image enters.
  - `scroll` ties it to the scroll position, both ways.
- `direction`: `up`, `down`, `left`, `right`

## Inputs and frames

Reads [`presence`](/docs/api/inputs#presence), [`size`](/docs/api/inputs#size). Draws only while something on it moves, then stops. Only while revealing, and with trigger scroll while scrolling; none at rest. See [how a frame is decided](/docs/concepts/frames).

## Reduced motion and touch

With reduced motion it is off and the element shows as plain HTML. Off: the image is shown as it is, and the engine does not load for it.

Runs on every device. The same as with a mouse: it follows the scroll.

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

start({ effects: { reveal: { reducedMotion: 'static' } } })
```

## Cost and quality

Loads 1.4 KB the first time a page uses it. GPU: One texture read of the image and one of a small noise tile per pixel. Memory: The shared texture of the image and a shared 64 x 64 noise tile.

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

## Recipes

### Cascade across a grid

Give each image a slightly longer `delay` than the one before it. The row enters together, so the prints open one after another from left to right.

Three prints that wipe in one after another.

```html title="index.html"
<div class="prints">
  <img src="/media/prints/dawn.jpg" alt="Dawn over the ridge" width="1000" height="1000" data-dio="reveal" />
  <img src="/media/prints/dusk.jpg" alt="Dusk over the paper hills" width="1000" height="1250" data-dio="reveal" data-dio-delay="0.15" />
  <img src="/media/prints/lanterns.jpg" alt="Paper lanterns rising over the hills at night" width="1000" height="1250" data-dio="reveal" data-dio-delay="0.3" />
</div>
```

```html title="panel.html"
<button type="button" data-replay>Replay</button>
<p>Each print waits 0.15 s longer than the one before it.</p>
```

```ts title="script.ts"
import { onScreen, replay, running, settle } from '../../replay.ts'

// Plays the cascade again on Replay, and once if the grid was on screen when the page opened.
export default function mount(example: HTMLElement): () => void {
  const prints = [...example.querySelectorAll('.prints img')]
  const button =
    example.querySelector<HTMLButtonElement>('[data-replay]')
  const again = () => {
    for (const print of prints) replay(print, 'reveal')
  }
  button?.addEventListener('click', again)
  const first = prints[0]
  if (first && onScreen(first))
    void Promise.all(prints.map((p) => running(p, 'reveal'))).then(
      (ok) => ok.every(Boolean) && again(),
    )
  return () => {
    button?.removeEventListener('click', again)
    for (const print of prints) settle(print)
  }
}
```

### Scrub it with the scroll

With `data-dio-trigger="scroll"` the reveal follows the scroll position both ways: the image opens as it rises to the middle of the viewport and closes again when you scroll back. Use it for a wide image that a reader passes slowly, such as a panorama between two sections.

```html
<img
  src="/media/ridges.jpg"
  data-dio="reveal"
  data-dio-trigger="scroll"
  data-dio-direction="right"
/>
```

### A quiet fade for long reads

The `fade` style drops the edge and drifts the image 40 px into place. Set `zoom` to 1 as well and an article’s figures arrive without drawing attention away from the text.

```html
<img
  src="/media/prints/night.jpg"
  data-dio="reveal"
  data-dio-style="fade"
  data-dio-zoom="1"
  data-dio-duration="0.8"
/>
```

### Bands across a wide banner

The `blinds` style opens the image in bands, each half a reveal after the one before it. A low `softness` keeps the bands crisp, which suits a banner of flat shapes or type.

```html
<img
  src="/media/ridges.jpg"
  data-dio="reveal"
  data-dio-style="blinds"
  data-dio-direction="down"
  data-dio-softness="0.02"
/>
```

## Notes

An image that is already in view when the page opens stays as it is: the reveal plays only for images the reader scrolls to, so nothing on the first screen disappears to play an intro. The example on this page plays again after each change for the same reason.

The reveal starts when `threshold` of the image height is in view above the bottom tenth of the viewport. An image that only peeks in at the bottom edge has not been looked at yet, so it waits.

`style`, `trigger`, `direction` and `seed` rebuild the effect when they change. Set them in the markup rather than switching them while the image is on screen.

## Related

- [bend](/docs/effects/bend.md): Scroll speed bends the image like paper and splits its color channels.
- [compare](/docs/effects/compare.md): Two pictures in one box, before and after, split by a line you drag, hover or scroll.
- [flare](/docs/effects/flare.md): A lens flare or a glossy light sweep over a photo that follows the pointer or the scroll.
- [frost](/docs/effects/frost.md): Frosted glass over a photo, or over the whole page, that the pointer wipes clear and that slowly fogs back.
- [glitch](/docs/effects/glitch.md): A digital glitch in short bursts: blocks slide sideways, color channels split, scanlines flicker.
- [image](/docs/effects/image.md): Draws the image or video unchanged, as a GL copy that page flights and other effects build on.
- [liquid](/docs/effects/liquid.md): The pointer leaves a fluid trail on a photo that settles back like water.
- [parallax](/docs/effects/parallax.md): The image drifts inside its frame with the pointer and the scroll; with a depth map, in 2.5D.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
