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

wave

TextAlso inScroll scenes

@dioramajs/text/waveSource

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.

View as Markdown
On this page

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.

Switch the trigger or the axis to play it again. With the hover trigger, point at the headline.
Params of wave
trigger

view sends one pulse when the text enters.

axis

y lifts the letters.

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.

Terminal window
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.

ParamTypeDefaultDescription
triggerrebuildsdata-dio-trigger'view' | 'loop' | 'hover' | 'scroll''view'
  • view sends one pulse when the text enters.
  • loop floats the letters on an endless wave.
  • hover sends a pulse each time the pointer or focus reaches it.
  • scroll ties the pulse to the scroll position, both ways.
axisrebuildsdata-dio-axis'y' | 'rotate' | 'scale' | 'flip''y'
  • y lifts the letters.
  • rotate rocks them.
  • scale swells them from the baseline.
  • flip tips their tops towards the viewer.
amplitudedata-dio-amplitudenumber0 to 1 em0.25Height 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-wavelengthnumber1 to 30 em6Loop trigger: distance between two crests.
speeddata-dio-speednumber0 to 30.5Loop trigger: waves per second; 0 holds the wave still.
durationdata-dio-durationnumber0.1 to 3 s0.7View, hover and scroll: time one letter takes to rise and settle.
staggerdata-dio-staggernumber0 to 0.3 s0.04View, hover and scroll: delay between neighboring letters.
delaydata-dio-delaynumber0 to 2 s0Wait after the trigger, for a cascade.
thresholddata-dio-thresholdnumber0 to 10.2Share of the element height in view, above the bottom tenth, before it plays.
fpsdata-dio-fpsnumber0 to 6030Loop 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.

TierWhat changes
lowThe 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.

Params of wave
<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>

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.