shimmer
A heading becomes polished chrome, gold, holographic foil or clear glass that catches the light as the pointer moves.
Meridian 07 · a limited run of 500
Meridian
A titanium case, a sapphire crystal and a movement that runs for ten days on one wind.
Live preview needs WebGPU or WebGL 2. A watch launch on a dark page whose heavy heading is polished chrome, with reflections that slide as the pointer moves.
This example failed to draw.
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. 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 shimmer<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>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.sm-headline', 'shimmer', { style: 'chrome', trigger: 'hover', bevel: 0.08, angle: 110, width: 1, strength: 1, follow: 1, shadow: 0.5,})import { start } from '@dioramajs/diorama'import shimmer from '@dioramajs/text/shimmer'
const app = start()app.attach('.sm-headline', shimmer({ style: 'chrome', trigger: 'hover', bevel: 0.08, angle: 110, width: 1, strength: 1, follow: 1, shadow: 0.5,}))Page transitions
The letters and their shadow fade 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 |
|---|---|---|---|
stylerebuildsdata-dio-style | 'chrome' | 'gold' | 'holo' | 'glass' | 'chrome' |
|
triggerrebuildsdata-dio-trigger | 'hover' | 'loop' | 'view' | 'pointer' | 'hover' |
|
colorsrebuildsdata-dio-colors | string | '' | CSS colors that tint the material, spaces apart; empty uses its own colors. |
beveldata-dio-bevel | number0 to 0.2 em | 0.08 | Width of the rounded edge of each letter in ems of the font size; 0 is flat. |
angledata-dio-angle | number0 to 360° | 110 | Direction the light sweeps in, in degrees like a CSS gradient: 90 is to the right. |
widthdata-dio-width | number0.3 to 3 | 1 | Width of the sweeping light or the pointer lamp; larger is a softer, wider glint. |
speeddata-dio-speed | number0 to 3 | 1 | Pace of the sweep and the loop; 0 never sweeps. |
strengthdata-dio-strength | number0 to 3 | 1 | Brightness of the moving light, the glitter and the light inside glass; 0 for none. |
followdata-dio-follow | number0 to 2 | 1 | How far the reflections turn with the pointer and the scroll; 0 holds them still. |
shadowdata-dio-shadow | number0 to 1 | 0.5 | Darkness of the soft shadow the letters cast on the page; 0 for none. |
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, pointer, progress, reducedMotion, size and 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. 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. 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.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { shimmer: { reducedMotion: 'off' } } })Cost and quality
- Download
- 11.8 KB min+gzip 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.
- 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 and its bevel are rastered at 1 device pixel per CSS pixel instead of 2. |
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.
Welcome back, Dana. Your books for October are closed and reconciled.
Live preview needs WebGPU or WebGL 2. The header of a bookkeeping app on a cream page, with a gold Pro badge beside its name that glints every few seconds.
This example failed to draw.
<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.
Friday, 10:00 CET · 300 pairs
Aurora Runner
Live preview needs WebGPU or WebGL 2. A sneaker drop announcement on a pale gray page, the shoe name in holographic foil lit by a lamp at the pointer.
This example failed to draw.
<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.
<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.