dots
A dot grid behind a hero or in a card that answers the pointer: dots near it grow, move aside or glow, then settle back.
Changelog, version 4.2
Preview links for every pull request
Each branch gets its own URL in about forty seconds, and review comments stay pinned to the exact pixel.
Live preview needs WebGPU or WebGL 2. A dark changelog hero with a dot grid beside the heading; dots near the pointer grow and turn periwinkle.
This example failed to draw.
Usage
Put it on an empty decorative element behind the content, such as an aria-hidden div filling a hero or the top of a card; a CSS dot pattern on it is the look without WebGL. start() registers dots, 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 dots<section class="dt-hero"> <div class="dt-copy"> <p class="dt-kicker">Changelog, version 4.2</p> <h2>Preview links for every pull request</h2> <p>Each branch gets its own URL in about forty seconds, and review comments stay pinned to the exact pixel.</p> </div> <div class="dt-grid" aria-hidden="true" data-dio="dots" data-dio-color="#4a5366" data-dio-accent="#8fa2ff" data-dio-radius="120" data-dio-strength="0.85" data-dio-fade="0.45" ></div></section>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.dt-grid', 'dots', { style: 'dots', mode: 'grow', gap: 24, dot: 2, color: '#4a5366', accent: '#8fa2ff', radius: 120, strength: 0.85, speed: 0, fade: 0.45,})import { start } from '@dioramajs/diorama'import dots from '@dioramajs/backgrounds/dots'
const app = start()app.attach('.dt-grid', dots({ style: 'dots', mode: 'grow', gap: 24, dot: 2, color: '#4a5366', accent: '#8fa2ff', radius: 120, strength: 0.85, speed: 0, fade: 0.45,}))Page transitions
Fades with the page transition. 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 | 'dots' | 'plus' | 'squares' | 'dots' |
|
moderebuildsdata-dio-mode | 'grow' | 'push' | 'glow' | 'grow' |
|
gapdata-dio-gap | number8 to 64 px | 24 | Distance between mark centers in CSS pixels. |
dotdata-dio-dot | number1 to 8 px | 2 | Mark size in CSS pixels: a dot's diameter or a square's side; a plus is 4 times wider. |
colordata-dio-color | color | '#a3acb9' | Color of the marks at rest, any CSS color. |
accentdata-dio-accent | color | '#5b6cff' | Color marks take under the pointer, any CSS color. |
radiusdata-dio-radius | number0 to 400 px | 140 | Reach of the pointer lens in CSS pixels; 0 turns the pointer off. |
strengthdata-dio-strength | number0 to 1 | 0.6 | Strength of the lens: how much marks grow, move or glow; 0 turns it off. |
speeddata-dio-speed | number0 to 40 px/s | 0 | Speed at which the grid slides; 0 keeps it in place.At most low 0 by quality tier. |
fadedata-dio-fade | number0 to 1 | 0 | How far the grid fades out toward the edges, from none to the middle. |
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, over, pointer, reducedMotion, size and width
. Draws at a steady rate while it is on screen and stops when it leaves. Frames only while the pointer moves over the grid and for about a second while the lens settles; with speed, up to 30 frames a second while on screen. 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. A still grid: no slide and no lens.
Runs on every device. No lens on touch screens, so a finger never draws frames; the slide still runs and scrolling works as usual.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { dots: { reducedMotion: 'off' } } })Cost and quality
- Download
- 2.0 KB min+gzip the first time a page uses it
- GPU
- One pass over the element with a little math per pixel; push draws the nine nearest marks per pixel.
- Memory
- None beyond the shared plane.
- 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 | No slide: the grid moves only under the pointer. |
Recipes
Behind a SaaS hero
Put the grid on an empty aria-hidden element that fills the hero and start the app with canvas: 'behind', so the heading and buttons sit over the canvas. A CSS dot pattern with the same gap and color is what visitors see before the engine draws and without WebGL. Raise fade so the grid dissolves before the edges of the hero.
<header class="hero"> <div class="hero-dots" aria-hidden="true" data-dio="dots" data-dio-fade="0.6" data-dio-color="#cbd2dc" data-dio-accent="#4f46e5" ></div> <h1>Ship docs your team reads</h1> <a class="cta" href="/signup">Start writing</a></header>.hero { position: relative; isolation: isolate; min-height: 80vh;}.hero-dots { position: absolute; inset: 0; z-index: -1; background: radial-gradient(circle, #cbd2dc 1px, transparent 1.5px) 0 0 / 24px 24px;}import { start } from '@dioramajs/diorama'
export const app = start({ canvas: 'behind' })Keep the hero itself without a background color, or it covers the canvas behind it. A background color on the grid element is fine: the effect draws it under the dots.
Plus marks on a blueprint
The plus style with push suits engineering and architecture products: thin plus marks on a pale panel slide out of the pointer’s way and settle back when it leaves.
Live preview needs WebGPU or WebGL 2. Thin blue plus marks on a pale blue panel, moving aside around the pointer.
This example failed to draw.
<div class="dt-blueprint" aria-hidden="true" data-dio="dots" data-dio-style="plus" data-dio-mode="push" data-dio-gap="32" data-dio-color="#9db4d6" data-dio-accent="#1f5fd1" data-dio-radius="130" data-dio-strength="0.9"></div>A drifting glow for a dark section
With speed the grid slides slowly even without a pointer, which keeps a pricing or sign-up section alive on phones. glow lights the squares under the pointer with a soft halo.
<div class="signup-bg" aria-hidden="true" data-dio="dots" data-dio-style="squares" data-dio-mode="glow" data-dio-speed="8" data-dio-gap="18" data-dio-dot="3" data-dio-color="#2a3140" data-dio-accent="#ffb347" data-dio-fade="0.7"></div>Notes
The docs canvas sits above the page, so the examples here keep text beside the grid instead of over it. Put text over a grid with canvas: 'behind', as in the first recipe.
The grid starts at the element’s top left corner, like a CSS background pattern, so a radial-gradient with the same gap matches it dot for dot. The element’s background color is read once, when the effect starts.
dots draws a frame only while the pointer moves over it and for about a second while the lens settles. With speed above 0 it draws up to 30 frames a second while on screen. On the low quality tier drift is off.
style and mode rebuild the effect when they change. The rest change live.