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

ribbon

TextAlso in3D and product

@dioramajs/text/ribbonSource

A headline printed on waving 3D fabric: a flag in the wind, a twisting satin ribbon or slow rippling silk.

View as Markdown
On this page

Harbor Half Marathon · 12 April 2027

Run the bay

21.1 kilometers along the waterfront, over two bridges and into the old town. Entries close on 1 March.

Live preview needs WebGPU or WebGL 2. A half marathon headline in white capitals on an orange label that waves like a flag over a night-blue page, its folds lit and casting a soft shadow.

This example failed to draw.

Switch the style and the trigger, or move the sliders. Move the pointer over the label to press a dent into the cloth.
Params of ribbon
style

flag is pinned at the left.

trigger

loop waves all the time.

Usage

Put it on a heading or short text in a large font, optionally with a solid background color and padding. Not img, video, canvas, svg or form fields. start() registers ribbon, 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 ribbon
<section class="rb-race">
<p class="rb-kicker">Harbor Half Marathon · 12 April 2027</p>
<h2 class="rb-label" data-dio="ribbon">Run the bay</h2>
<p class="rb-line">21.1 kilometers along the waterfront, over two bridges and into the old town. Entries close on 1 March.</p>
</section>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.rb-label', 'ribbon', {
style: 'flag',
trigger: 'loop',
wind: 1,
speed: 1,
folds: 2.5,
twist: 180,
gloss: 0.6,
})
import { start } from '@dioramajs/diorama'
import ribbon from '@dioramajs/text/ribbon'
const app = start()
app.attach('.rb-label', ribbon({
style: 'flag',
trigger: 'loop',
wind: 1,
speed: 1,
folds: 2.5,
twist: 180,
gloss: 0.6,
}))

Page transitions

The cloth fades with the page. 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'flag' | 'ribbon' | 'silk''flag'
  • flag is pinned at the left.
  • ribbon twists along each line.
  • silk ripples with a sheen.
triggerrebuildsdata-dio-trigger'loop' | 'hover' | 'scroll''loop'
  • loop waves all the time.
  • hover raises the wind under the pointer.
  • scroll follows the scroll speed.
winddata-dio-windnumber0 to 21How deep the folds are; 0 keeps the cloth flat apart from the twist and dent.
speeddata-dio-speednumber0 to 31How fast the waves travel; 0 freezes them in place.
foldsdata-dio-foldsnumber1 to 82.5Number of waves along the cloth.
twistdata-dio-twistnumber0 to 360°180Largest turn of the ribbon's rolling twist; past 90 its back shows.
glossdata-dio-glossnumber0 to 20.6Strength of the glossy highlight on the folds; 0 leaves only the shading.
backrebuildsdata-dio-backstring''Color of the back of the cloth; empty uses a darker shade of the surface or text color.
colorrebuildsdata-dio-colorstring''Surface color behind the text, drawn at rest too; empty uses the element's own background.

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, over, pointer, reducedMotion, size, width, x and y . Draws at a steady rate while it is on screen and stops when it leaves. With trigger loop, every frame while on screen; with hover and scroll, only while the cloth moves and settles, none at rest. How a frame is decided.

Reduced motion and touch

With reduced motion it shows a still frame: motion inputs are zero and time stands still. The cloth stays flat and still: the plain text shows, or the flat copy with its color when color is set.

Runs on every device. There is no dent without a mouse. With trigger hover, a tap blows a gust that settles again; scroll works as on desktop.

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

import { start } from '@dioramajs/diorama'
start({ effects: { ribbon: { reducedMotion: 'off' } } })

Cost and quality

Download
10.5 KB min+gzip the first time a page uses it
GPU
A grid of a few thousand vertices per heading, each placed by three evaluations of the waves for its normal, drawn twice: once as the cloth and once flattened as its shadow. One texture read per pixel, a blurred one for the shadow.
Memory
A canvas of the text at twice its CSS size with mip levels, and the grid geometry.
Frames
Draws while on screen

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, the cloth grid is half as dense, and it waves at 30 frames per second.
mediumThe cloth grid is a little coarser.

Recipes

A satin ribbon for a grand opening

style="ribbon" turns each line into a strip of satin. The strip waves, and a twist rolls along it from left to right: where it turns past edge-on you see the back of the ribbon in back, a darker shade of the surface when you leave it out. color paints the ribbon behind the letters and stays on the page at rest too. A larger twist turns the strip further; at 360 it makes a full roll and comes back to the printed side.

Saturday 6 March, from 10 a.m.

Grand opening

Fieldhouse Bakery, 18 Mill Lane. The first hundred guests take home a loaf.

Live preview needs WebGPU or WebGL 2. A bakery's grand opening headline in cream capitals on a red satin ribbon that twists to its dark back as it waves, on a cream page.

This example failed to draw.

Params of ribbon
<div class="rb-opening">
<p>Saturday 6 March, from 10 a.m.</p>
<h2
class="rb-opening-title"
data-dio="ribbon"
data-dio-style="ribbon"
data-dio-color="#c8102e"
data-dio-back="#6e0a1c"
>Grand opening</h2>
<p>Fieldhouse Bakery, 18 Mill Lane. The first hundred guests take home a loaf.</p>
</div>

Silk for a fashion label

style="silk" lays the letters on silk with slow, shallow ripples from three directions while a broad sheen sweeps across. Without a surface color the cloth is the letters themselves, so it suits a light serif or a refined sans in a pale gold. Raise gloss for a glossier fabric.

Autumn / Winter 2027

Maison Lune

Bias-cut slip dresses in washed silk, shown in Paris on 3 March.

Live preview needs WebGPU or WebGL 2. A fashion house name in pale gold letters rippling like silk, with a sheen sliding across, on a dark plum page.

This example failed to draw.

Params of ribbon
<div class="rb-silk">
<p class="rb-silk-kicker">Autumn / Winter 2027</p>
<h2
class="rb-silk-title"
data-dio="ribbon"
data-dio-style="silk"
data-dio-gloss="1.2"
>Maison Lune</h2>
<p class="rb-silk-line">Bias-cut slip dresses in washed silk, shown in Paris on 3 March.</p>
</div>

A label that waves while the page scrolls

With trigger="scroll" the wind follows the scroll speed: a quick flick sends a wave through the label, and once the page stops the cloth settles flat and hands back to the DOM. A solid background color and padding on the heading become the cloth, so the label looks the same at rest with or without the effect.

<h2
class="label"
data-dio="ribbon"
data-dio-trigger="scroll"
>Match day</h2>

Notes

The cloth is a real 3D surface, not a distortion of the picture. A grid of a few thousand points is folded by travelling waves and seen with its own perspective, the normal of each point comes from the shape of the folds, and the light from the top left shades the cloth by them: folds turned away darken, crests catch a highlight whose strength is gloss. The same cloth, flattened along the light, is drawn on the page behind as a soft shadow that blurs the higher the cloth lifts. The text is printed on the cloth from a raster of the heading, so the letters bend with it.

A flag is pinned at its left edge and swings wider toward the free end. folds sets how many waves run along the cloth and wind how deep they are; the folds keep the same steepness on a short word and on a long line. The pointer presses a dent into the cloth that follows it.

The heading stays real text in the DOM: screen readers read it, search engines index it, and find in page works. With trigger="hover" and trigger="scroll" the cloth lies flat at rest and the DOM text shows, so nothing is drawn until the wind picks up. A solid background color on the heading itself becomes the surface of the cloth, with its border radius. A background image or a border on the heading is hidden while it waves, so put those on a wrapper; a background image on the heading itself keeps the text as it is.

color paints a surface the page does not have, so the flat copy of the cloth stays drawn at rest in place of the DOM text. Under reduced motion the cloth stays flat and still. The canvas cannot draw some text the way the browser does: background-clip: text, text-shadow, -webkit-text-stroke and vertical writing modes. An element with any of them keeps its text as it is, and a warning in development names the reason. style, trigger, back and color rebuild the effect when they change.