frost
Frosted glass over a photo, or over the whole page, that the pointer wipes clear and that slowly fogs back.
Live preview needs WebGPU or WebGL 2. A bay with dark islets behind frosted glass; the pointer wipes a clear patch that slowly fogs back over.
This example failed to draw.
Usage
Put it on img, video, body, any element. start() registers frost, 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 frost<figure class="fr-window"> <img src="/media/coast/islets-960.avif" width="960" height="960" data-dio="frost" style="touch-action: none" /></figure>import { start } from '@dioramajs/diorama'
const app = start()app.attach('img', 'frost', { style: 'frost', by: 'pointer', blur: 22, strength: 0.45, grain: 0.5, radius: 70, refog: 4, refill: 1, duration: 1.2, start: 0.15, end: 0.5, cover: 1, x: 0.5, y: 0.5, middle: 0, color: '#eef3f7',})import { start } from '@dioramajs/diorama'import frost from '@dioramajs/media/frost'
const app = start()app.attach('img', frost({ style: 'frost', by: 'pointer', blur: 22, strength: 0.45, grain: 0.5, radius: 70, refog: 4, refill: 1, duration: 1.2, start: 0.15, end: 0.5, cover: 1, x: 0.5, y: 0.5, middle: 0, color: '#eef3f7',}))Page transitions
Fades with the page transition; no wipes are taken while it plays. 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 | 'frost' | 'steam' | 'frost' | frost: ice crystals over a milky layer; steam: a fogged mirror with droplets. |
byrebuildsdata-dio-by | 'pointer' | 'hover' | 'view' | 'scroll' | 'pointer' | pointer: the pointer wipes the glass; hover: it clears from where the pointer came in and fogs back when it leaves; view: it clears once as the photo comes into view; scroll: it clears with the scroll between start and end. The pointer wipes in every mode but hover. |
blurdata-dio-blur | number0 to 40 px | 22 | Blur of the photo behind the glass: 0 keeps it sharp. The pane over a page draws no blur, since it never reads the page.At most low 6 by quality tier. |
strengthdata-dio-strength | number0 to 1 | 0.45 | How much the glass veils the photo in color: 0 leaves only the blur. |
graindata-dio-grain | number0 to 1 | 0.5 | Strength of the ice crystals, or the share of droplets in steam style: 0 is plain glass. |
radiusdata-dio-radius | number10 to 300 px | 70 | Radius of the wipe under the pointer. |
refogdata-dio-refog | number0 to 20 s | 4 | Seconds a wiped area takes to fog back, and with by hover the fog after the pointer leaves: 0 keeps it clear. |
refilldata-dio-refill | number0 to 1 | 1 | How much of the fog comes back over a wiped area: 1 all of it, 0.3 a thin layer that keeps the page readable, 0 none. |
durationdata-dio-duration | number0 to 4 s | 1.2 | Length of the clearing with by hover and by view, and of a freeze or thaw. |
startdata-dio-start | number0 to 1 | 0.15 | With by scroll, the scroll progress at which the clearing begins: 0 as the photo enters at the bottom. |
enddata-dio-end | number0 to 1 | 0.5 | With by scroll, the scroll progress at which the glass is clear: 0.5 is about the photo centred in the viewport. |
coverdata-dio-cover | number0 to 1 | 1 | How much of the glass is frozen: rising, ice grows in from the edges over duration; falling, it thaws outwards from x, y. 0 is bare glass. Live, so a script or a scroll handler can freeze and thaw the page. |
xdata-dio-x | number0 to 1 | 0.5 | Where a thaw starts, from the left edge of the box (the viewport on <body>). |
ydata-dio-y | number0 to 1 | 0.5 | Where a thaw starts, from the top edge. |
middledata-dio-middle | number0 to 1 | 0 | How much thinner the ice is in the middle of the pane, so text there stays readable: 0 frosts it evenly, 1 leaves the middle clear. Screens without hover use at least 0.6. |
keeprebuildsdata-dio-keep | string | '' | A CSS selector of up to six elements the pane keeps a thin veil over, such as the headline and the button, so they stay readable under thick ice. Read when the effect starts; a photo ignores it. |
colordata-dio-color | color | '#eef3f7' | Tint of the glass, a cold white by default. |
resolutionrebuildsdata-dio-resolution | number16 to 256 | 64 | Cells across each side of the wipe mask: more gives a finer edge.At most low 32 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, presence, reducedMotion, size, width, x and y
. Draws only while something on it moves, then stops. Only while the pointer wipes, while a wipe fogs back, while a clearing plays and while the ice grows or thaws; none at rest. With by scroll only while the page scrolls. 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. No animated clearing, freeze or thaw: they jump to where they end. On a photo wiping still works and wiped areas still fog back. The pane over a page is only a faint cold tint without crystals, and nothing wipes it.
Runs on every device. On a photo a pressed finger wipes the glass; a scroll takes the gesture, so add touch-action: none to the image to wipe without scrolling. The pane over a page never takes a gesture: every touch clears the ice around it, also while it scrolls, and the middle stays thin. With by hover a tap clears the glass for good. by view and by scroll need no gesture.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { frost: { reducedMotion: 'off' } } })Cost and quality
- Download
- 6.3 KB min+gzip the first time a page uses it
- GPU
- On a photo seventeen texture reads per pixel for the blur (nine on low), two of the noise tile and one of the mask; steam adds one for the droplets. The pane reads the noise tile four times and the mask once per pixel of its area, with no blur.
- Memory
- The image, a shared 128 × 128 noise tile and a mask of resolution × resolution bytes × 4.
- Frames
- Idle at rest
It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.
| Tier | What changes |
|---|---|
low | Blur at most 6 px with 8 reads instead of 16; a 32 × 32 mask. The pane drops its finest crystals. |
Recipes
Wipe the window to see the product
For winter campaigns and “reveal the product” teasers, the visitor wipes the glass like a cold window. touch-action: none lets a finger wipe instead of scrolling the page.
<img src="/winter/parka.avif" data-dio="frost" style="touch-action: none"/>A steamed mirror that clears on hover
style="steam" draws a fogged mirror with droplets; by="hover" clears it while the pointer is over the photo and refog sets how fast it fogs back.
<img src="/spa/bath.avif" data-dio="frost" data-dio-style="steam" data-dio-by="hover" data-dio-refog="2"/>A teaser that thaws on scroll
With by="scroll" the glass clears between start and end as the image scrolls into view.
<img src="/launch/bottle.avif" data-dio="frost" data-dio-by="scroll" data-dio-start="0.1" data-dio-end="0.45"/>A frozen window over the whole page
On any element that is not a picture, frost draws a pane of ice over its box; on a fixed element over the viewport (or on <body>) the whole screen freezes. Nothing under it is read: the page stays real, readable and clickable, and the pointer wipes the ice from anywhere on the window. keep names the text the ice stays thin over, refill lets only a thin fog come back over a wiped patch, and cover freezes the glass from the edges and thaws it from x, y.
<div class="window" data-dio="frost" data-dio-cover="0" data-dio-strength="0.12" data-dio-refill="0.35" data-dio-keep=".hero h1, .hero .cta" style="position: fixed; inset: 0; pointer-events: none"></div>// Freeze when the winter section comes on screen, thaw when it leaves.document.querySelector('.window').dataset.dioCover = inWinter ? '1' : '0'On touch screens a finger never wipes, since that would fight the scroll: every touch clears the ice around it, also while it scrolls, and the middle of the screen stays thin. Pair it with drops for meltwater running down after a thaw.
Notes
The photo stays a plain <img> with its alt text, so the frost never hides what the picture shows from a screen reader. Under reduced motion nothing clears by itself: with by="view" or "scroll" the photo shows clear, wiping still works. A cleared patch is kept when the quality tier changes.
On a pane the ice under reduced motion is only a faint cold tint without crystals, and nothing wipes it.
style, by, keep and resolution rebuild the effect; the other params change live.