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

waves

BackgroundsAlso inScroll scenes

@dioramajs/backgrounds/wavesSource

Topographic contour lines or flowing wave lines across a hero or footer, slowly changing and shifted by scroll.

View as Markdown
On this page

Day hike, Zailiysky Alatau

Big Almaty Lake loop

Distance
14.2 km
Climb
860 m
Time
5 to 6 h

Pine forest to the dam, then open ridges with the lake below. Best from June to September.

Live preview needs WebGPU or WebGL 2. A trail card whose map is drawn as brown contour lines on paper, slowly changing shape, next to the route's distance, climb and time.

This example failed to draw.

Switch style to waves for flowing lines or to stripes for filled bands.
Params of waves
style

contour draws the lines of a topographic map over a slowly changing relief.

Usage

Put it on an empty decorative element behind the content, such as an aria-hidden div filling a hero or a footer; its CSS background is the look without WebGL. start() registers waves, 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 waves
<article class="wv-route">
<div
class="wv-map"
aria-hidden="true"
data-dio="waves"
data-dio-color="#8a7a5c"
data-dio-background="#efe8d8"
data-dio-lines="18"
data-dio-thickness="1"
></div>
<div class="wv-info">
<p class="wv-kicker">Day hike, Zailiysky Alatau</p>
<h2>Big Almaty Lake loop</h2>
<dl>
<div><dt>Distance</dt><dd>14.2 km</dd></div>
<div><dt>Climb</dt><dd>860 m</dd></div>
<div><dt>Time</dt><dd>5 to 6 h</dd></div>
</dl>
<p>Pine forest to the dam, then open ridges with the lake below. Best from June to September.</p>
</div>
</article>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.wv-map', 'waves', {
style: 'contour',
lines: 18,
color: '#8a7a5c',
background: '#efe8d8',
warp: 0.5,
speed: 0.3,
thickness: 1,
scroll: 0.3,
fps: 30,
})
import { start } from '@dioramajs/diorama'
import waves from '@dioramajs/backgrounds/waves'
const app = start()
app.attach('.wv-map', waves({
style: 'contour',
lines: 18,
color: '#8a7a5c',
background: '#efe8d8',
warp: 0.5,
speed: 0.3,
thickness: 1,
scroll: 0.3,
fps: 30,
}))

Page transitions

Fades with the page transition. 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'contour' | 'waves' | 'stripes''contour'
  • contour draws the lines of a topographic map over a slowly changing relief.
  • waves draws lines flowing across the element.
  • stripes fills every other band between those lines.
linesdata-dio-linesnumber2 to 6016Lines across the height of the element; more lines pack them closer.
colordata-dio-colorcolor'#3b6a8f'Color of the lines or stripes, any CSS color.
backgrounddata-dio-backgroundcolor'#0c1424'Color behind the lines, any CSS color.
warpdata-dio-warpnumber0 to 10.5How far noise bends the lines; 0 draws straight parallel lines.
speeddata-dio-speednumber0 to 20.3How fast the relief and the swells change; 0 keeps their shape.
thicknessdata-dio-thicknessnumber0.5 to 6 px1.2Line width in CSS pixels; stripes ignore it.
scrolldata-dio-scrollnumber0 to 10.3How far the lines move while the element crosses the viewport.
fpsdata-dio-fpsnumber0 to 6030Most frames a second the motion draws; 0 holds it still.At most low 15, medium 24 by quality tier.
seedrebuildsdata-dio-seednumber1 to 1001Shape of the noise that bends the lines.

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, progress, reducedMotion and size . Draws at a steady rate while it is on screen and stops when it leaves. Up to fps frames a second while on screen, none off screen or at fps 0; scroll draws at full rate. 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. A still frame: the lines neither change nor move with scroll.

Runs on every device. Nothing changes on touch screens: scroll moves the lines as usual.

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

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

Cost and quality

Download
2.1 KB min+gzip the first time a page uses it
GPU
One pass over the element: four or eight reads of a small noise tile per pixel.
Memory
A 128 × 128 noise tile in half floats per element, 128 KB.
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
lowAt most 15 frames a second.
mediumAt most 24 frames a second.

Recipes

Contours behind a hero

Put the lines on an empty aria-hidden element that fills the hero and start the app with canvas: 'behind'. The element’s CSS background is what visitors see before the engine draws and without WebGL, so give it the same color as background.

<header class="hero">
<div
class="hero-bg"
aria-hidden="true"
data-dio="waves"
data-dio-color="#2f5d50"
data-dio-background="#0d1f1a"
></div>
<h1>Trails for every season</h1>
<a class="cta" href="/maps">Browse the maps</a>
</header>
.hero {
position: relative;
isolation: isolate;
min-height: 80vh;
}
.hero-bg {
position: absolute;
inset: 0;
z-index: -1;
background: #0d1f1a;
}
src/main.ts
import { start } from '@dioramajs/diorama'
export const app = start({ canvas: 'behind' })

The waves style runs the lines across the element in soft swells. More lines and a low warp give a calm, technical texture for a footer or a dashboard header, and scroll moves them as the footer comes into view.

<footer class="site-footer">
<div
class="footer-bg"
aria-hidden="true"
data-dio="waves"
data-dio-style="waves"
data-dio-lines="28"
data-dio-warp="0.4"
data-dio-color="#24406b"
data-dio-background="#0a1428"
data-dio-scroll="0.6"
></div>
<p>Ledger, money for teams</p>
</footer>

Bold stripes for a campaign band

stripes fills every other band, for a loud poster look on a sale or festival page.

Live preview needs WebGPU or WebGL 2. Orange and peach wavy bands across a wide strip, slowly changing shape.

This example failed to draw.

Params of waves
<div
class="wv-band"
aria-hidden="true"
data-dio="waves"
data-dio-style="stripes"
data-dio-lines="9"
data-dio-warp="0.7"
data-dio-color="#ff7a45"
data-dio-background="#ffd9b8"
></div>

Notes

The docs canvas sits above the page, so the examples here keep text beside the lines instead of over them. Put text over the lines with canvas: 'behind', as in the first recipe.

Lines keep their width in CSS pixels wherever they run. Where they crowd together they blend into an even tone, and where the relief is flat they fade, so the picture never flickers or blots.

It draws up to fps frames a second while it is on screen and none off screen; scroll draws at full rate while it moves the lines. On the low tier it draws at most 15 frames a second. Set fps to 0 for lines that move only with scroll.

style and seed rebuild the effect when they change. The colors, line count and speeds change live.