# 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.

When the heading scrolls into view a wave runs through it from left to right: each letter lifts and settles in turn, like a crowd doing the wave in a stadium. Other axes rock the letters, swell them or tip their tops towards you. With the loop trigger the letters float on an endless wave instead, for a festival title or a playful brand line. Between pulses the heading is the real text: selectable, crisp and styled by your CSS.

Module `text`, category Text. Import `@dioramajs/text/wave`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/text/src/wave.ts)

A festival poster headline whose letters lift one after another as a wave runs through them.

```html title="index.html"
<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>
```

## 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.

```html
<h1 data-dio="wave">Summer Sound Festival</h1>
```

In page transitions: The copy fades with the page.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `trigger` (rebuilds) | `data-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. |
| `axis` (rebuilds) | `data-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. |
| `amplitude` | `data-dio-amplitude` | `number` 0 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. |
| `wavelength` | `data-dio-wavelength` | `number` 1 to 30 em | `6` | Loop trigger: distance between two crests. |
| `speed` | `data-dio-speed` | `number` 0 to 3 | `0.5` | Loop trigger: waves per second; 0 holds the wave still. |
| `duration` | `data-dio-duration` | `number` 0.1 to 3 s | `0.7` | View, hover and scroll: time one letter takes to rise and settle. |
| `stagger` | `data-dio-stagger` | `number` 0 to 0.3 s | `0.04` | View, hover and scroll: delay between neighboring letters. |
| `delay` | `data-dio-delay` | `number` 0 to 2 s | `0` | Wait after the trigger, for a cascade. |
| `threshold` | `data-dio-threshold` | `number` 0 to 1 | `0.2` | Share of the element height in view, above the bottom tenth, before it plays. |
| `fps` | `data-dio-fps` | `number` 0 to 60 | `30` | Loop trigger: most frames per second; the pulses always run at full rate. At most low 24. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `trigger`: `view`, `loop`, `hover`, `scroll`
  - `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.
- `axis`: `y`, `rotate`, `scale`, `flip`
  - `y` lifts the letters.
  - `rotate` rocks them.
  - `scale` swells them from the baseline.
  - `flip` tips their tops towards the viewer.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`size`](/docs/api/inputs#size), [`y`](/docs/api/inputs#input-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. See [how a frame is decided](/docs/concepts/frames).

## 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.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { wave: { reducedMotion: 'static' } } })
```

## Cost and quality

Loads 7.3 KB 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.

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

See [the quality plugin](/docs/effects/quality).

## 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.

An event title whose letters float on a slow, endless wave.

```html title="index.html"
<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.

```html
<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.

```html
<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.

## Related

- [assemble](/docs/effects/assemble.md): Thousands of lit particles fly out of the depth around the page and gather into a heading.
- [blinds](/docs/effects/blinds.md): A heading printed across real 3D slats that turn over in a wave, lit and casting shadows, to show it.
- [counter](/docs/effects/counter.md): Stats count up to their value on real 3D mechanics: odometer drums, slot machine reels or flip cards.
- [dust](/docs/effects/dust.md): A heading crumbles into fine sand that lifts off the page and drifts away in depth as it scrolls out, or on a click.
- [emboss](/docs/effects/emboss.md): Letters pressed into or raised out of paper, leather, brushed metal, stone or plaster, lit by a light that follows the pointer.
- [extrude](/docs/effects/extrude.md): A headline becomes a solid 3D block: beveled letters with lit side walls, seen in perspective, that turn toward the pointer.
- [fire](/docs/effects/fire.md): The letters burn: flames rise from their tops, sparks drift up in depth and the firelight flickers on the page.
- [hologram](/docs/effects/hologram.md): A heading becomes a 3D hologram: projected from a glowing emitter, built of slices in depth, crossed by scan lines.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
