liquid
The pointer leaves a fluid trail on a photo that settles back like water.
Live preview needs WebGPU or WebGL 2. Surf rolling onto a rocky shore; where the pointer passes, the picture bends as if under moving water, then settles.
This example failed to draw.
Usage
Put it on img, video. start() registers liquid, 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 liquid<img class="wave" src="/media/coast/surf-1440.avif" width="1440" height="960" data-dio="liquid" style="touch-action: pan-y"/>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.wave', 'liquid', { style: 'water', strength: 1, radius: 80, duration: 1.5, swirl: 0.5, shine: 0.5, split: 1,})import { start } from '@dioramajs/diorama'import liquid from '@dioramajs/media/liquid'
const app = start()app.attach('.wave', liquid({ style: 'water', strength: 1, radius: 80, duration: 1.5, swirl: 0.5, shine: 0.5, split: 1,}))Page transitions
Fades with the page transition, which takes the image without its trail. 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 | 'water' | 'smear' | 'prism' | 'water' |
|
strengthdata-dio-strength | number0 to 3 | 1 | How far the trail moves the picture: 0 turns the effect off. |
radiusdata-dio-radius | number10 to 300 px | 80 | Width of the trail around the path. |
durationdata-dio-duration | number0.2 to 5 s | 1.5 | Time the trail takes to settle after the pointer stops. |
swirldata-dio-swirl | number0 to 2 | 0.5 | How much the wake drifts along itself as it fades: 0 keeps it in place. |
shinedata-dio-shine | number0 to 2 | 0.5 | Light on the edges of the wake in water style: 0 refracts without light. |
splitdata-dio-split | number0 to 4 | 1 | Width of the color fringes in prism style: 0 leaves the colors together. |
resolutionrebuildsdata-dio-resolution | number16 to 128 | 64 | Cells of the trail along each side of the image: more is finer and costs more CPU.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 height, presence, size and 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. How a frame is decided.
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.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { liquid: { reducedMotion: 'static' } } })Cost and quality
- Download
- 2.3 KB min+gzip 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.
- 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 | At most 32 cells per side. |
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.
<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.
<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.
<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.