# curtain

A cover picture opens from behind a curtain as you scroll: strips slide away, halves part or a liquid edge drains past.

The picture starts covered by a curtain of a solid color or a second picture. As the element scrolls toward the middle of the screen, or as its pinned section scrolls, the curtain opens and casts a soft shadow on the picture at its edge, while the picture settles from a slight zoom. strips slide off one after another, each carrying its slice of the curtain; split parts two halves from the seam, gathering in folds; liquid drains past with a wavy edge and a light rim. Scrolling back closes it again, and with out it closes before the section lets go. Once open it is the picture as it is.

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

The cover of a case study, the drawing room of a house above the sea, which opens from behind a dark curtain as it scrolls toward the middle of the screen.

```html title="index.html"
<div class="cover">
  <img src="/media/house/drawing-room.avif" alt="The drawing room: sofas, a stone wall and tall windows onto the garden" width="1000" height="667" data-dio="curtain" data-dio-load="eager" />
  <p class="cover-title"><span>Case study</span> Casa Alta, a house above the sea</p>
</div>
```

## Usage

Put it on: img, video; for by pin, on a sticky stage inside a tall section.

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

```html
<img src="/img/cover.avif" alt="Harbour at dawn" style="width: 100%; aspect-ratio: 16 / 9; object-fit: cover" data-dio="curtain" data-dio-color="#f4f1ea" />
```

In page transitions: Leaving a page closes the curtain, entering opens it up to where the scroll has it. A picture on the first screen waits behind a veil until the curtain is drawn.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'strips' \| 'split' \| 'liquid'` | `'strips'` | strips slide off one after another; split parts two halves from the seam with folds; liquid drains past with a wavy edge. |
| `by` (rebuilds) | `data-dio-by` | `'view' \| 'pin' \| 'manual'` | `'view'` | view opens it as the element scrolls from the bottom of the screen to its middle; pin follows the pinned section; manual only position. |
| `direction` (rebuilds) | `data-dio-direction` | `'auto' \| 'up' \| 'down' \| 'left' \| 'right'` | `'auto'` | Where the curtain goes: up opens from the bottom. split parts sideways for left and right, up and down for up and down. auto parts split sideways, like a stage curtain, and lifts the others. |
| `position` | `data-dio-position` | `number` 0 to 1 | `0` | Opening set by hand, 0 shut to 1 open; with view or pin the least opening. |
| `start` | `data-dio-start` | `number` 0 to 1 | `0.15` | Progress at which it starts to open. |
| `end` | `data-dio-end` | `number` 0 to 1 | `0.85` | Progress at which it is open. |
| `out` | `data-dio-out` | `number` 0 to 1 | `1` | Progress from which it closes again; 1 keeps it open. |
| `count` | `data-dio-count` | `number` 1 to 12 | `5` | Strips of strips, folds of each half in split, waves of the liquid edge. |
| `color` | `data-dio-color` | `color` | `'#0b0b0c'` | Color of the curtain, or what shows while src loads. |
| `src` (rebuilds) | `data-dio-src` | `string` | `''` | A second picture to use as the curtain, framed like the image, such as a sketch, a title card or the brand pattern. |
| `zoom` | `data-dio-zoom` | `number` 0 to 1.5 | `1.1` | Scale the picture settles from; 1 or 0 for none. |
| `shade` | `data-dio-shade` | `number` 0 to 1 | `0.5` | Depth of the shadow at the edge, the folds of split and the rim of liquid; 0 flat. |
| `ease` | `data-dio-ease` | `number` 0 to 1 s | `0` | Smoothing behind scroll; 0 follows it at once (Lenis already smooths it). |
| `seed` (rebuilds) | `data-dio-seed` | `number` 1 to 100 | `1` | Shape of the liquid edge. |

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

### Variants

- `style`: `strips`, `split`, `liquid`
  - `strips` slide off one after another.
  - `split` parts two halves from the seam with folds.
  - `liquid` drains past with a wavy edge.
- `by`: `view`, `pin`, `manual`
  - `view` opens it as the element scrolls from the bottom of the screen to its middle.
  - `pin` follows the pinned section.
  - `manual` only position.
- `direction`: `auto`, `up`, `down`, `left`, `right`

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`presence`](/docs/api/inputs#presence), [`size`](/docs/api/inputs#size), [`y`](/docs/api/inputs#input-y). Draws only while something on it moves, then stops. Scroll draws its own frames, ease keeps drawing until it settles. 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 picture is shown as it is, without the curtain, 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: { curtain: { reducedMotion: 'static' } } })
```

## Cost and quality

Loads 2.1 KB the first time a page uses it. GPU: One texture read of the image per pixel, one more with src, and one of a small noise tile for liquid. Memory: The image, the src picture when given and a shared 64 x 64 noise tile.

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

## Recipes

### A case study cover

The cover opens from behind a curtain as the visitor reaches it, and closes again on the way back. A curtain in the color of the page reads as the page itself opening.

```html
<img src="/img/cover.avif" alt="Harbour at dawn" style="width: 100%; aspect-ratio: 16 / 9; object-fit: cover" data-dio="curtain" data-dio-color="#f4f1ea" />
```

### A chapter opening in a pinned section

With `by="pin"` the curtain follows the pinned section. `out` closes it again before the section lets go, so the next chapter starts from a closed curtain.

```html
<section style="height: 250vh">
  <div style="position: sticky; top: 0; height: 100vh">
    <img src="/img/valley.avif" alt="The valley at dusk" style="width: 100%; height: 100%; object-fit: cover" data-dio="curtain" data-dio-by="pin" data-dio-style="split" data-dio-end="0.5" data-dio-out="0.85" />
  </div>
</section>
```

`split` parts the halves sideways like a theater curtain by default; `direction="up"` or `"down"` parts them up and down instead.

### From the plan to the photo

`src` makes a second picture the curtain, framed like the image: a plan, a sketch, a title card or a brand pattern.

```html
<img src="/img/terrace.avif" alt="The terrace above the sea" style="object-fit: cover" data-dio="curtain" data-dio-style="liquid" data-dio-src="/img/ground-floor.webp" />
```

### Driven by GSAP

`by="manual"` leaves the opening to `position`, for a timeline or a button.

```ts
const cover = app.effects.get(document.querySelector('.cover'), 'curtain')
gsap.to(cover.params, { position: 1, duration: 1.2, ease: 'power2.inOut' })
```

## Notes

Unlike `reveal`, which brings a picture in from transparency, `curtain` draws the curtain itself: strips that carry their slice away, halves with folds or a wavy liquid edge, with a soft shadow on the picture. Open, it is the picture as it is.

A picture on the first screen waits behind a veil until the curtain is drawn, so the bare picture never flashes before it closes. Under reduced motion the effect is off and the picture is shown as it is.

`style`, `by`, `direction`, `src` and `seed` rebuild the effect; the others change live.

## Related

- [expand](/docs/effects/expand.md): The image of a card grows to fill its sticky stage as the section scrolls.
- [horizontal](/docs/effects/horizontal.md): A row of cards on a pinned stage slides sideways as the page scrolls down, its pictures bending with the speed.
- [sequence](/docs/effects/sequence.md): An image sequence scrubbed by scroll, frame by frame, from a poster <img>.
- [zoom-scroll](/docs/effects/zoom-scroll.md): A picture in a pinned section zooms from its box to fill the screen as you scroll.
- [ambient](/docs/effects/ambient.md): A soft glow in the colors of the frame around a video or an image, like ambient mode.
- [assemble](/docs/effects/assemble.md): Thousands of lit particles fly out of the depth around the page and gather into a heading.
- [bend](/docs/effects/bend.md): Scroll speed bends the image like paper and splits its color channels.
- [blinds](/docs/effects/blinds.md): A heading printed across real 3D slats that turn over in a wave, lit and casting shadows, to show it.
- [How a layer follows scroll](/docs/concepts/scroll.md)
