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

unfold

TextAlso in3D and productScroll scenes

@dioramajs/text/unfoldSource

A headline unfolds out of the page like paper: strips, a zig-zag band, letter cards or folded squares open in 3D.

View as Markdown
On this page

Mailbox Press · Porto

Letters from the coast, folded by hand

Cards and notes printed on cotton paper, posted the same week.

Live preview needs WebGPU or WebGL 2. A letterpress studio's headline that unrolls out of a folded paper packet line by line, each strip swinging down in perspective with its shadow on the page.

This example failed to draw.

Switch the style to see the accordion, the letter cards and the origami squares, or move the sliders; Replay plays it again.

Every switch and slider plays it again.

Params of unfold
style

strips rolls down.

Usage

Put it on a heading or short text block in a large font. Not img, video, canvas, svg or form fields. start() registers unfold, 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 unfold
<div class="fd-hero">
<p class="fd-kicker">Mailbox Press · Porto</p>
<h2
class="fd-headline"
data-dio="unfold"
>Letters from the coast, folded by hand</h2>
<p class="fd-line">Cards and notes printed on cotton paper, posted the same week.</p>
</div>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.fd-headline', 'unfold', {
style: 'strips',
angle: 180,
duration: 0.9,
stagger: 0.3,
shade: 0.7,
})
import { start } from '@dioramajs/diorama'
import unfold from '@dioramajs/text/unfold'
const app = start()
app.attach('.fd-headline', unfold({
style: 'strips',
angle: 180,
duration: 0.9,
stagger: 0.3,
shade: 0.7,
}))

Page transitions

Leaving a page folds the paper back up, entering one unfolds it; at rest it leaves as text. 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' | 'accordion' | 'cards' | 'origami''strips'
  • strips rolls down.
  • accordion stretches.
  • cards stands letters up.
  • origami opens squares.
triggerrebuildsdata-dio-trigger'view' | 'scroll' | 'hover''view'
  • view opens it once in view.
  • scroll scrubs with the page.
  • hover folds a little under the pointer.
bandsrebuildsdata-dio-bandsnumber | 'auto'1 to 24'auto'Strips, pleats or rows of squares; auto cuts one per line, or a pleat per two ems.
angledata-dio-anglenumber30 to 180°180How far each piece is folded before it opens; 180 lies folded flat.
durationdata-dio-durationnumber0.3 to 2.5 s0.9Time one piece takes to open.
staggerdata-dio-staggernumber0 to 1 s0.3Time between neighboring pieces, shortened so all start within 1.4 durations.
paperdata-dio-papercolor'#f8f5ee'Color of the backs of the pieces, the paper seen while folded.
shadedata-dio-shadenumber0 to 10.7Strength of the shading on the faces and at the folds; 0 keeps flat colors.
delaydata-dio-delaynumber0 to 2 s0Wait between the trigger and the first fold.
thresholddata-dio-thresholdnumber0 to 10.2Share of the heading in view that opens it with the view trigger, or starts the scrub.

Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.

Inputs and frames

It reads height, presence, progress, size and y . Draws only while something on it moves, then stops. While the paper opens, and with the scroll trigger while scrolling through it; with the hover trigger while the pointer moves over it and the folds settle; 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 heading stays flat text.

Runs on every device. With trigger hover a tap folds the pieces under the finger for a moment.

To change what reduced motion does, patch it in start().

import { start } from '@dioramajs/diorama'
start({ effects: { unfold: { reducedMotion: 'static' } } })

Cost and quality

Download
13.1 KB min+gzip the first time a page uses it
GPU
Three instanced draws of a quad per piece (lying flat, raised, and their shadows) while the paper moves; nothing at rest.
Memory
A canvas of the text at twice its CSS size with mip levels and a 256 px tile of paper fiber.
Frames
Idle at rest

It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.

TierWhat changes
lowThe text is rastered at 1 device pixel per CSS pixel instead of 2.

Recipes

Letter cards for an event title

style="cards" gives every letter its own little card, hinged at the bottom of its line. Before it opens each card lies face down below its line, showing the paper back with the letter faintly through it; then the cards flip up one after another, standing out of the page halfway and casting a shadow, and land as the title. paper sets the color of the backs: a warm cream reads as card stock.

12 to 20 April · Old Tram Depot

Paper Week

Pop-up books, paper engineering and a folding bar for kids.

Live preview needs WebGPU or WebGL 2. A pop-up book exhibition called Paper Week, whose coral letters flip up on cream cards one after another.

This example failed to draw.

Params of unfold
<div class="fd-show">
<p class="fd-show-date">12 to 20 April · Old Tram Depot</p>
<h2
class="fd-show-title"
data-dio="unfold"
data-dio-style="cards"
data-dio-paper="#fff6dc"
>Paper Week</h2>
<p class="fd-show-line">Pop-up books, paper engineering and a folding bar for kids.</p>
</div>

An accordion sale banner

style="accordion" cuts the text into upright panels folded like a paper fan. Closed, the panels stand in a tight zig-zag with the letters squeezed between the folds; opening, they stretch apart sideways, the panels facing the light brighten and the others darken, until the banner lies flat. A heading with text-align: center opens from its middle, otherwise from the side it is aligned to. bands sets the number of panels.

Summer sale

Up to 40% off linen, until Sunday night.

Live preview needs WebGPU or WebGL 2. A summer sale banner in black capitals on a yellow band that stretches open like an accordion.

This example failed to draw.

Params of unfold
<div class="fd-sale">
<h2
class="fd-sale-title"
data-dio="unfold"
data-dio-style="accordion"
data-dio-paper="#fffdf4"
>Summer sale</h2>
<p>Up to 40% off linen, until Sunday night.</p>
</div>

With data-dio-trigger="hover" the text stays flat and real until the pointer moves over it; then the pieces nearest the pointer fold up a little toward the viewer and lie back down when it moves on. With cards that is a wave of letters following the pointer. On a phone a tap folds the letters under the finger for a moment.

<nav>
<a href="/shop">
<span
data-dio="unfold"
data-dio-style="cards"
data-dio-trigger="hover"
>Shop</span>
</a>
<a href="/journal">
<span
data-dio="unfold"
data-dio-style="cards"
data-dio-trigger="hover"
>Journal</span>
</a>
</nav>

Origami squares scrubbed by the scroll

data-dio-trigger="scroll" ties the opening to the scroll position: it starts when threshold of the heading is in view and is flat when the heading reaches the middle of the viewport, and it folds back up when you scroll back. With style="origami" each line becomes a row of squares as tall as the line, each folded corner to center.

<h2
data-dio="unfold"
data-dio-style="origami"
data-dio-trigger="scroll"
>Studio Kami</h2>

Notes

The paper is real geometry: each piece is a flat panel turning on its hinge in 3D, and the pieces that hang from it turn with it, seen with the perspective of the heading’s own box. The light comes from the top left. Faces turned toward it brighten and faces turned away darken, the inside of every fold darkens toward its crease, and the raised paper casts a soft shadow on the page that grows wider the higher the paper is. shade scales all of that shading; at 0 the paper keeps flat colors.

The fronts of the pieces take the color of the page behind the heading, so when they lie flat they disappear into it and only the letters remain. When the heading sits on a picture or a gradient instead, the fronts are clear and turn to paper only while they are lifted. Put a background on a wrapper rather than on the heading itself: while the paper is drawn the heading’s own background is hidden with its text.

The heading stays real text in the DOM: screen readers read it, search engines index it, and find in page works. A heading on the first screen is hidden until the folded paper is drawn and then opens; one further down waits folded until threshold of it is in view. Frames run only while the paper moves; once it lies flat the DOM text is back and nothing is drawn. Under reduced motion the effect is off and the heading stays flat text.

Leave some room around the heading: paper standing out of the page and its shadow reach past the heading’s box. The canvas cannot draw background-clip: text, text-shadow, -webkit-text-stroke or vertical writing modes the way the browser does: an element with any of them keeps its text as it is, and a warning in development names the reason. style, mode and bands rebuild the effect when they change; the other params change live.