Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

curtain

Scroll scenesAlso inPhoto

@dioramajs/media/curtainSource

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

View as Markdown
On this page
The drawing room: sofas, a stone wall and tall windows onto the garden

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.

Scroll the page. Scroll back up and the curtain closes again; switch the style for halves that part or a liquid edge.
Params of curtain
style

strips slide off one after another.

by

view opens it as the element scrolls from the bottom of the screen to its middle.

direction

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.

Terminal window
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.

ParamTypeDefaultDescription
stylerebuildsdata-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.
byrebuildsdata-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.
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-positionnumber0 to 10Opening set by hand, 0 shut to 1 open; with view or pin the least opening.
startdata-dio-startnumber0 to 10.15Progress at which it starts to open.
enddata-dio-endnumber0 to 10.85Progress at which it is open.
outdata-dio-outnumber0 to 11Progress from which it closes again; 1 keeps it open.
countdata-dio-countnumber1 to 125Strips of strips, folds of each half in split, waves of the liquid edge.
colordata-dio-colorcolor'#0b0b0c'Color of the curtain, or what shows while src loads.
srcrebuildsdata-dio-srcstring''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-zoomnumber0 to 1.51.1Scale the picture settles from; 1 or 0 for none.
shadedata-dio-shadenumber0 to 10.5Depth of the shadow at the edge, the folds of split and the rim of liquid; 0 flat.
easedata-dio-easenumber0 to 1 s0Smoothing behind scroll; 0 follows it at once (Lenis already smooths it).
seedrebuildsdata-dio-seednumber1 to 1001Shape 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.