wave
The letters of a heading ride a wave: one pulse when it comes into view, on hover or with the scroll, or an endless float.
July 18 to 20, Riverside Park
Summer Sound Festival
Live preview needs WebGPU or WebGL 2. A festival poster headline whose letters lift one after another as a wave runs through them.
This example failed to draw.
Usage
Put it on a heading, a label, a link or a button with text. Not img, video, canvas, svg or form fields. start() registers wave, 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 wave<div class="wv-poster"> <p class="wv-date">July 18 to 20, Riverside Park</p> <h2 class="wv-title" data-dio="wave" >Summer Sound Festival</h2></div>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.wv-title', 'wave', { trigger: 'view', axis: 'y', amplitude: 0.25, wavelength: 6, speed: 0.5, duration: 0.7, stagger: 0.04, delay: 0, threshold: 0.2, fps: 30,})import { start } from '@dioramajs/diorama'import wave from '@dioramajs/text/wave'
const app = start()app.attach('.wv-title', wave({ trigger: 'view', axis: 'y', amplitude: 0.25, wavelength: 6, speed: 0.5, duration: 0.7, stagger: 0.04, delay: 0, threshold: 0.2, fps: 30,}))Page transitions
The copy 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.
| Param | Type | Default | Description |
|---|---|---|---|
triggerrebuildsdata-dio-trigger | 'view' | 'loop' | 'hover' | 'scroll' | 'view' |
|
axisrebuildsdata-dio-axis | 'y' | 'rotate' | 'scale' | 'flip' | 'y' |
|
amplitudedata-dio-amplitude | number0 to 1 em | 0.25 | Height of the wave in em for y; for rotate and flip a quarter turn per 1 (0.25 is 22.5°); for scale the growth (0.25 is 125%). 0 turns the effect off. |
wavelengthdata-dio-wavelength | number1 to 30 em | 6 | Loop trigger: distance between two crests. |
speeddata-dio-speed | number0 to 3 | 0.5 | Loop trigger: waves per second; 0 holds the wave still. |
durationdata-dio-duration | number0.1 to 3 s | 0.7 | View, hover and scroll: time one letter takes to rise and settle. |
staggerdata-dio-stagger | number0 to 0.3 s | 0.04 | View, hover and scroll: delay between neighboring letters. |
delaydata-dio-delay | number0 to 2 s | 0 | Wait after the trigger, for a cascade. |
thresholddata-dio-threshold | number0 to 1 | 0.2 | Share of the element height in view, above the bottom tenth, before it plays. |
fpsdata-dio-fps | number0 to 60 | 30 | Loop trigger: most frames per second; the pulses always run at full rate.At most low 24 by quality tier. |
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, size and y
. Draws at a steady rate while it is on screen and stops when it leaves. Only while a pulse runs, and with the scroll trigger while scrolling; the loop draws at most fps frames a second while on screen. 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 text is shown as it is, and the engine does not load for it.
Runs on every device. The same as with a mouse, except that the hover trigger needs keyboard focus on touch.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { wave: { reducedMotion: 'static' } } })Cost and quality
- Download
- 7.3 KB min+gzip the first time a page uses it
- GPU
- One instanced draw of a quad per letter, one texture read per pixel.
- Memory
- A canvas of the text at twice its CSS size with mip levels, kept while the element lives.
- 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 | The text is rastered at 1 device pixel per CSS pixel instead of 2, and the loop draws at most 24 frames a second. |
Recipes
A title that floats all the time
data-dio-trigger="loop" keeps the letters on an endless wave, which suits a festival name or a playful brand line in a hero. Keep amplitude small and speed slow so the line stays readable. The loop draws at most fps frames a second, 30 by default, and none while the title is off screen.
Open all weekend
Live preview needs WebGPU or WebGL 2. An event title whose letters float on a slow, endless wave.
This example failed to draw.
<div class="wv-float"> <p class="wv-name" data-dio="wave" data-dio-trigger="loop" data-dio-amplitude="0.15" >Open all weekend</p></div>Navigation links that rock on hover
With data-dio-trigger="hover" a link stays as plain text and sends a short wave through its letters each time the pointer or keyboard focus reaches it. The rotate axis rocks the letters instead of lifting them, and a short duration lets the wave finish before the visitor clicks.
<a href="/tickets" data-dio="wave" data-dio-trigger="hover" data-dio-axis="rotate" data-dio-duration="0.45" data-dio-stagger="0.03">Get tickets</a>A section title tied to the scroll
data-dio-trigger="scroll" moves the wave with the scroll position, so it runs forward as the title comes up and back when the visitor scrolls up. The flip axis tips the tops of the letters towards the viewer, like a row of cards in a stadium.
<h2 data-dio="wave" data-dio-trigger="scroll" data-dio-axis="flip" data-dio-amplitude="0.6">Lineup, day one</h2>Notes
The heading keeps its text as you wrote it, with no span per letter, so screen readers, search engines and find in page see the real words. Between waves the element is the real, selectable text. A heading on screen when the page opens plays as soon as the effect is ready: the wave starts and ends with the text as laid out, so nothing flashes.
wavelength and speed belong to the loop; duration and stagger to the single waves of the other modes. amplitude="0" turns the effect off and shows the text, and speed="0" holds the loop still. Under reduced motion the effect is off and the engine does not load for it.
The canvas cannot draw background-clip: text, text-shadow, -webkit-text-stroke or vertical writing modes the way the browser does, so such a heading stays as it is, with a warning in development. An underline is hidden while the letters move. trigger and axis rebuild the effect when they change; the other params change live.