# shimmer

A heading becomes polished chrome, gold, holographic foil or clear glass that catches the light as the pointer moves.

Every letter gets a rounded bevel built from its own shape and is lit as a real material in a small photo studio: a bright sky over a sharp horizon, a dark floor, a softbox overhead and tall strips at the sides. The reflections slide over the letters as the pointer moves and the page scrolls, a light sweeps across them on hover, as they come into view or on a loop, and a soft shadow falls on the page beside them. Chrome and gold are mirror metals, holo is a rainbow foil whose colors shift with the viewing angle and glitter in fine points, and glass is clear in the middle with bright or dark rims and light gathered inside its edges.

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

A watch launch on a dark page whose heavy heading is polished chrome, with reflections that slide as the pointer moves.

```html title="index.html"
<div class="sm-hero">
  <p class="sm-kicker">Meridian 07 · a limited run of 500</p>
  <h2 class="sm-headline" data-dio="shimmer">Meridian</h2>
  <p class="sm-line">A titanium case, a sapphire crystal and a movement that runs for ten days on one wind.</p>
</div>
```

## Usage

Put it on: a large heading, a logo word or a short label in a bold font, on a dark or a light page. Not img, video, canvas, svg or form fields.

`start()` registers `shimmer`, so the attribute alone puts it on an element.

```html
<h1 class="hero" data-dio="shimmer">Chrome Edition</h1>
```

In page transitions: The letters and their shadow fade with the page.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'chrome' \| 'gold' \| 'holo' \| 'glass'` | `'chrome'` | chrome a mirror metal; gold a warm metal; holo a rainbow foil; glass clear tinted letters. |
| `trigger` (rebuilds) | `data-dio-trigger` | `'hover' \| 'loop' \| 'view' \| 'pointer'` | `'hover'` | hover sweeps on pointer, focus or tap; loop every few seconds; view once; pointer a lamp. |
| `colors` (rebuilds) | `data-dio-colors` | `string` | `''` | CSS colors that tint the material, spaces apart; empty uses its own colors. |
| `bevel` | `data-dio-bevel` | `number` 0 to 0.2 em | `0.08` | Width of the rounded edge of each letter in ems of the font size; 0 is flat. |
| `angle` | `data-dio-angle` | `number` 0 to 360° | `110` | Direction the light sweeps in, in degrees like a CSS gradient: 90 is to the right. |
| `width` | `data-dio-width` | `number` 0.3 to 3 | `1` | Width of the sweeping light or the pointer lamp; larger is a softer, wider glint. |
| `speed` | `data-dio-speed` | `number` 0 to 3 | `1` | Pace of the sweep and the loop; 0 never sweeps. |
| `strength` | `data-dio-strength` | `number` 0 to 3 | `1` | Brightness of the moving light, the glitter and the light inside glass; 0 for none. |
| `follow` | `data-dio-follow` | `number` 0 to 2 | `1` | How far the reflections turn with the pointer and the scroll; 0 holds them still. |
| `shadow` | `data-dio-shadow` | `number` 0 to 1 | `0.5` | Darkness of the soft shadow the letters cast on the page; 0 for none. |

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

### Variants

- `style`: `chrome`, `gold`, `holo`, `glass`
  - `chrome` a mirror metal.
  - `gold` a warm metal.
  - `holo` a rainbow foil.
  - `glass` clear tinted letters.
- `trigger`: `hover`, `loop`, `view`, `pointer`
  - `hover` sweeps on pointer, focus or tap.
  - `loop` every few seconds.
  - `view` once.
  - `pointer` a lamp.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`pointer`](/docs/api/inputs#pointer), [`progress`](/docs/api/inputs#progress), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`size`](/docs/api/inputs#size), [`width`](/docs/api/inputs#input-width). Draws at a steady rate while it is on screen and stops when it leaves. None at rest: the material is drawn once and stays. Full rate while the light sweeps and while the reflections settle after the pointer, one frame per scroll or pointer move, and with trigger loop nothing between sweeps. See [how a frame is decided](/docs/concepts/frames).

## Reduced motion and touch

With reduced motion it shows a still frame: motion inputs are zero and time stands still. The material is drawn still: no sweeps, and the reflections no longer follow the pointer or the scroll.

Runs on every device. The reflections still turn with the scroll; with trigger hover a tap sweeps the light, and with trigger pointer the lamp follows a finger while it touches the text.

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

start({ effects: { shimmer: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 11.8 KB the first time a page uses it. GPU: One instanced quad per line of text, three or four texture reads and a few dozen operations per pixel. Memory: A canvas of the text at twice its CSS size and a half-float map of the bevel, built once on the CPU from a distance field of the letters.

- low: The text and its bevel are rastered at 1 device pixel per CSS pixel instead of 2.

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

## Recipes

### A gold plan badge that glints

`style="gold"` with `trigger="loop"` sweeps a light over a short label every few seconds and draws nothing in between. A smaller `bevel` suits small text, where a wide bevel would round the letters off. Gold reads well on a light page; `colors` turns it into rose or white gold.

The header of a bookkeeping app on a cream page, with a gold Pro badge beside its name that glints every few seconds.

```html title="index.html"
<div class="sm-app">
  <header class="sm-bar">
    <span class="sm-logo">Fernbook</span>
    <span class="sm-plan" data-dio="shimmer" data-dio-style="gold" data-dio-trigger="loop" data-dio-bevel="0.06">Pro</span>
  </header>
  <p class="sm-welcome">Welcome back, Dana. Your books for October are closed and reconciled.</p>
</div>
```

### Holographic foil for a limited drop

`style="holo"` turns the letters into a rainbow foil whose colors move with the viewing angle, with fine glitter that flashes as the angle changes. With `trigger="pointer"` a lamp follows the pointer over the letters. On a light page the foil is deeper and more saturated so the name stays readable. Point at the name below.

A sneaker drop announcement on a pale gray page, the shoe name in holographic foil lit by a lamp at the pointer.

```html title="index.html"
<div class="sm-drop">
  <p class="sm-date">Friday, 10:00 CET · 300 pairs</p>
  <h2 class="sm-name" data-dio="shimmer" data-dio-style="holo" data-dio-trigger="pointer">Aurora Runner</h2>
</div>
```

### Glass that sweeps once in view

`style="glass"` draws clear letters with a tinted rim, tinted by the text color or the first of `colors`. On a dark page the rim catches the light; on a light page it darkens like the edge of real glass, and the shadow carries the tint with a little gathered light inside it.

```html
<h2 data-dio="shimmer" data-dio-style="glass" data-dio-trigger="view" data-dio-colors="#4aa8ff">Clear thinking</h2>
```

## Notes

The bevel is built from the shape of each letter: a distance field of the text gives every pixel its distance to the nearest edge, and a rounded profile over `bevel` turns that into a slope, so the edges catch the studio’s lights the way a real bevel would. Each line also curves back a little at the top and bottom, which is what puts the horizon of the studio across the middle of chrome letters. The outline and anti-aliasing of the letters are the browser’s own: the shape is read from a raster of the text, not redrawn.

The reflections follow the pointer anywhere on the page and turn as the heading scrolls through the viewport. After the pointer stops they settle in a fraction of a second and nothing more is drawn. Set `follow` to 0 to hold them still, and `speed` to 0 to turn the sweep off.

The heading stays real text in the DOM: screen readers read it, search engines index it, and find in page works. A CSS filter hides the DOM text while the material is drawn, so give the text a color that reads on its own, since that is what shows without WebGL. Text on screen when the page opens is hidden until the material is ready, at most a few seconds.

Use a bold, large font: the bevel needs room, and thin strokes show little of the material. The canvas cannot draw `background-clip: text`, `-webkit-text-stroke` or vertical writing modes the way the browser does, and an element with any of them keeps its text as it is, with a warning in development. A `text-shadow` is fine: the effect casts its own shadow instead.

`style`, `trigger` and `colors` rebuild the effect when they change. `bevel` builds the surface again a moment after it changes; 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)
