# liquid

The pointer leaves a fluid trail on a photo that settles back like water.

Where the pointer passes, the picture bends as if seen through moving water: a wake follows the path, spreads, drifts a little and fades out over duration, after which the copy matches the image again. Unlike ripple, which draws rings around a hovering pointer for as long as it stays, liquid reacts only to movement, follows the path the pointer took and goes still on its own.

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

Surf rolling onto a rocky shore; where the pointer passes, the picture bends as if under moving water, then settles.

```html title="index.html"
<img class="wave" src="/media/coast/surf-1440.avif" alt="Surf rolling in over dark rocks" width="1440" height="960" data-dio="liquid" style="touch-action: pan-y" />
```

## Usage

Put it on: img, video.

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

```html
<img src="/studio/reef.avif" alt="Coral reef in clear shallow water" data-dio="liquid" />
```

In page transitions: Fades with the page transition, which takes the image without its trail.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'water' \| 'smear' \| 'prism'` | `'water'` | water refracts the picture by the slope of the wake and lights its edges; smear drags the picture along the path like a finger through wet paint; prism drags it and splits the trail into red and blue fringes. |
| `strength` | `data-dio-strength` | `number` 0 to 3 | `1` | How far the trail moves the picture: 0 turns the effect off. |
| `radius` | `data-dio-radius` | `number` 10 to 300 px | `80` | Width of the trail around the path. |
| `duration` | `data-dio-duration` | `number` 0.2 to 5 s | `1.5` | Time the trail takes to settle after the pointer stops. |
| `swirl` | `data-dio-swirl` | `number` 0 to 2 | `0.5` | How much the wake drifts along itself as it fades: 0 keeps it in place. |
| `shine` | `data-dio-shine` | `number` 0 to 2 | `0.5` | Light on the edges of the wake in water style: 0 refracts without light. |
| `split` | `data-dio-split` | `number` 0 to 4 | `1` | Width of the color fringes in prism style: 0 leaves the colors together. |
| `resolution` (rebuilds) | `data-dio-resolution` | `number` 16 to 128 | `64` | Cells of the trail along each side of the image: more is finer and costs more CPU. At most low 32. |

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

### Variants

- `style`: `water`, `smear`, `prism`
  - `water` refracts the picture by the slope of the wake and lights its edges.
  - `smear` drags the picture along the path like a finger through wet paint.
  - `prism` drags it and splits the trail into red and blue fringes.

## Inputs and frames

Reads [`height`](/docs/api/inputs#input-height), [`presence`](/docs/api/inputs#presence), [`size`](/docs/api/inputs#size), [`width`](/docs/api/inputs#input-width). Draws only while something on it moves, then stops. Only while a trail is settling, about duration after the last move; none at rest, and a still pointer draws nothing. See [how a frame is decided](/docs/concepts/frames).

## Reduced motion and touch

With reduced motion it is off and the element shows as plain HTML. Off: the image stays DOM and nothing loads for it.

Runs on every device. A pressed finger draws the trail. Without touch-action on the image a vertical swipe still scrolls the page, and the trail stops where the scroll takes over; add touch-action: none for drawing without scrolling.

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

start({ effects: { liquid: { reducedMotion: 'static' } } })
```

## Cost and quality

Loads 2.3 KB the first time a page uses it. GPU: One texture read per pixel for the trail plus the picture; three in prism style. Memory: A 64 × 64 half-float texture, 32 KB, besides the image.

- low: At most 32 cells per side.

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

## Recipes

### A hero photo under water

The default `water` style refracts the picture along the wake of the pointer and lights its edges with `shine`. It suits a studio landing page or a cover that should feel touchable without moving at rest.

```html
<img src="/studio/reef.avif" data-dio="liquid" />
```

### Covers smeared like wet paint

`style="smear"` drags the picture along the path instead, like a finger through wet paint. A wider `radius` and a longer `duration` make the strokes linger on a portfolio grid; `swirl="0"` keeps them where they were drawn.

```html
<img
  src="/work/poster.avif"
  data-dio="liquid"
  data-dio-style="smear"
  data-dio-radius="120"
  data-dio-duration="2.5"
/>
```

### Color fringes on a product shot

`style="prism"` smears the picture and splits the trail into red and blue fringes, as wide as `split` sets. With `touch-action: none` a finger draws without scrolling the page.

```html
<img
  src="/drops/sneaker.avif"
  data-dio="liquid"
  data-dio-style="prism"
  data-dio-split="2"
  style="touch-action: none"
/>
```

## Notes

`liquid` reacts to movement, not to hover: a pointer resting on the image draws nothing, and the trail stills on its own about `duration` after the last move. `ripple` is the opposite: rings around the pointer for as long as it hovers.

The trail is a small grid simulated on the CPU in fixed steps, so it looks the same at any frame rate and costs one extra texture read per pixel. Under reduced motion the effect is off and the image stays a plain `<img>`.

`style` and `resolution` rebuild the effect; every other param changes 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.
- [frost](/docs/effects/frost.md): Frosted glass over a photo, or over the whole page, that the pointer wipes clear and that slowly fogs back.
- [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.
- [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.
- [Follow the pointer](/docs/learn/pointer.md)
- [Reduced motion](/docs/guides/reduced-motion.md)
