waves
Topographic contour lines or flowing wave lines across a hero or footer, slowly changing and shifted by scroll.
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.
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.
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.
| Param | Type | Default | Description |
|---|---|---|---|
stylerebuildsdata-dio-style | 'contour' | 'waves' | 'stripes' | 'contour' |
|
linesdata-dio-lines | number2 to 60 | 16 | Lines across the height of the element; more lines pack them closer. |
colordata-dio-color | color | '#3b6a8f' | Color of the lines or stripes, any CSS color. |
backgrounddata-dio-background | color | '#0c1424' | Color behind the lines, any CSS color. |
warpdata-dio-warp | number0 to 1 | 0.5 | How far noise bends the lines; 0 draws straight parallel lines. |
speeddata-dio-speed | number0 to 2 | 0.3 | How fast the relief and the swells change; 0 keeps their shape. |
thicknessdata-dio-thickness | number0.5 to 6 px | 1.2 | Line width in CSS pixels; stripes ignore it. |
scrolldata-dio-scroll | number0 to 1 | 0.3 | How far the lines move while the element crosses the viewport. |
fpsdata-dio-fps | number0 to 60 | 30 | Most frames a second the motion draws; 0 holds it still.At most low 15, medium 24 by quality tier. |
seedrebuildsdata-dio-seed | number1 to 100 | 1 | Shape 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.
| Tier | What changes |
|---|---|
low | At most 15 frames a second. |
medium | At 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;}import { start } from '@dioramajs/diorama'
export const app = start({ canvas: 'behind' })Flowing lines in a fintech footer
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.
<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.