curtain
A cover picture opens from behind a curtain as you scroll: strips slide away, halves part or a liquid edge drains past.
Case study Casa Alta, a house above the sea
Live preview needs WebGPU or WebGL 2. 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.
This example failed to draw.
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. 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 curtain<div class="cover"> <img src="/media/house/drawing-room.avif" 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>import { start } from '@dioramajs/diorama'
const app = start()app.attach('img', 'curtain', { style: 'strips', by: 'view', direction: 'auto', position: 0, start: 0.15, end: 0.85, out: 1, count: 5, color: '#0b0b0c', zoom: 1.1, shade: 0.5, ease: 0,})import { start } from '@dioramajs/diorama'import curtain from '@dioramajs/media/curtain'
const app = start()app.attach('img', curtain({ style: 'strips', by: 'view', direction: 'auto', position: 0, start: 0.15, end: 0.85, out: 1, count: 5, color: '#0b0b0c', zoom: 1.1, shade: 0.5, ease: 0,}))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. 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 |
|---|---|---|---|
stylerebuildsdata-dio-style | 'strips' | 'split' | 'liquid' | 'strips' |
|
byrebuildsdata-dio-by | 'view' | 'pin' | 'manual' | 'view' |
|
directionrebuildsdata-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. |
positiondata-dio-position | number0 to 1 | 0 | Opening set by hand, 0 shut to 1 open; with view or pin the least opening. |
startdata-dio-start | number0 to 1 | 0.15 | Progress at which it starts to open. |
enddata-dio-end | number0 to 1 | 0.85 | Progress at which it is open. |
outdata-dio-out | number0 to 1 | 1 | Progress from which it closes again; 1 keeps it open. |
countdata-dio-count | number1 to 12 | 5 | Strips of strips, folds of each half in split, waves of the liquid edge. |
colordata-dio-color | color | '#0b0b0c' | Color of the curtain, or what shows while src loads. |
srcrebuildsdata-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. |
zoomdata-dio-zoom | number0 to 1.5 | 1.1 | Scale the picture settles from; 1 or 0 for none. |
shadedata-dio-shade | number0 to 1 | 0.5 | Depth of the shadow at the edge, the folds of split and the rim of liquid; 0 flat. |
easedata-dio-ease | number0 to 1 s | 0 | Smoothing behind scroll; 0 follows it at once (Lenis already smooths it). |
seedrebuildsdata-dio-seed | number1 to 100 | 1 | Shape of the liquid edge. |
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, presence, size and y
. Draws only while something on it moves, then stops. Scroll draws its own frames, ease keeps drawing until it settles. None at rest. How a frame is decided.
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.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { curtain: { reducedMotion: 'static' } } })Cost and quality
- Download
- 2.1 KB min+gzip 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.
- 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 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.
<img src="/img/cover.avif" 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.
<section style="height: 250vh"> <div style="position: sticky; top: 0; height: 100vh"> <img src="/img/valley.avif" 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.
<img src="/img/terrace.avif" 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.
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.