# frost

Frosted glass over a photo, or over the whole page, that the pointer wipes clear and that slowly fogs back.

The photo sits behind frosted glass: blurred, veiled in a pale tint and laced with ice crystals, or, in steam style, a fogged mirror dotted with droplets. Wiping the pointer across it clears a band with a ragged wet edge, which fogs back over refog seconds. Instead of wiping, the glass can clear from the pointer on hover, clear from the middle as the photo comes into view, or clear along with the scroll. On <body> the screen becomes a frozen window: feathers of ice grow in from the edges over a milky veil, glints catch the light near the pointer, and the page under it stays real, readable and clickable. On any other element the same pane covers its box. cover freezes the glass from the edges and thaws it outwards from a point.

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

A bay with dark islets behind frosted glass; the pointer wipes a clear patch that slowly fogs back over.

```html title="index.html"
<figure class="fr-window">
  <img src="/media/coast/islets-960.avif" alt="Dark islets in a blue bay, a ship on the horizon" width="960" height="960" data-dio="frost" style="touch-action: none" />
</figure>
```

## Usage

Put it on: img, video, body, any element.

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

```html
<img src="/winter/parka.avif" alt="Down parka on a hanger by a frosted window" data-dio="frost" style="touch-action: none" />
```

In page transitions: Fades with the page transition; no wipes are taken while it plays.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'frost' \| 'steam'` | `'frost'` | frost: ice crystals over a milky layer; steam: a fogged mirror with droplets. |
| `by` (rebuilds) | `data-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. |
| `blur` | `data-dio-blur` | `number` 0 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. |
| `strength` | `data-dio-strength` | `number` 0 to 1 | `0.45` | How much the glass veils the photo in color: 0 leaves only the blur. |
| `grain` | `data-dio-grain` | `number` 0 to 1 | `0.5` | Strength of the ice crystals, or the share of droplets in steam style: 0 is plain glass. |
| `radius` | `data-dio-radius` | `number` 10 to 300 px | `70` | Radius of the wipe under the pointer. |
| `refog` | `data-dio-refog` | `number` 0 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. |
| `refill` | `data-dio-refill` | `number` 0 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. |
| `duration` | `data-dio-duration` | `number` 0 to 4 s | `1.2` | Length of the clearing with by hover and by view, and of a freeze or thaw. |
| `start` | `data-dio-start` | `number` 0 to 1 | `0.15` | With by scroll, the scroll progress at which the clearing begins: 0 as the photo enters at the bottom. |
| `end` | `data-dio-end` | `number` 0 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. |
| `cover` | `data-dio-cover` | `number` 0 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. |
| `x` | `data-dio-x` | `number` 0 to 1 | `0.5` | Where a thaw starts, from the left edge of the box (the viewport on <body>). |
| `y` | `data-dio-y` | `number` 0 to 1 | `0.5` | Where a thaw starts, from the top edge. |
| `middle` | `data-dio-middle` | `number` 0 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. |
| `keep` (rebuilds) | `data-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. |
| `color` | `data-dio-color` | `color` | `'#eef3f7'` | Tint of the glass, a cold white by default. |
| `resolution` (rebuilds) | `data-dio-resolution` | `number` 16 to 256 | `64` | Cells across each side of the wipe mask: more gives a finer edge. At most low 32. |

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

### Variants

- `style`: `frost`, `steam`
- `by`: `pointer`, `hover`, `view`, `scroll`

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`presence`](/docs/api/inputs#presence), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`size`](/docs/api/inputs#size), [`width`](/docs/api/inputs#input-width), [`x`](/docs/api/inputs#input-x), [`y`](/docs/api/inputs#input-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. 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. 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.

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

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

## Cost and quality

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

- low: Blur at most 6 px with 8 reads instead of 16; a 32 × 32 mask. The pane drops its finest crystals.

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

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

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

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

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

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

```ts
// 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](/docs/effects/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.

## Related

- [bend](/docs/effects/bend.md): Scroll speed bends the image like paper and splits its color channels.
- [compare](/docs/effects/compare.md): Two pictures in one box, before and after, split by a line you drag, hover or scroll.
- [flare](/docs/effects/flare.md): A lens flare or a glossy light sweep over a photo that follows the pointer or the scroll.
- [glitch](/docs/effects/glitch.md): A digital glitch in short bursts: blocks slide sideways, color channels split, scanlines flicker.
- [image](/docs/effects/image.md): Draws the image or video unchanged, as a GL copy that page flights and other effects build on.
- [liquid](/docs/effects/liquid.md): The pointer leaves a fluid trail on a photo that settles back like water.
- [parallax](/docs/effects/parallax.md): The image drifts inside its frame with the pointer and the scroll; with a depth map, in 2.5D.
- [pixelate](/docs/effects/pixelate.md): The image resolves from big pixels to sharp as it scrolls into view, or breaks into pixels on hover.
- [Reduced motion](/docs/guides/reduced-motion.md)
