ripple
Rings spread from the pointer while the image is hovered.
Live preview needs WebGPU or WebGL 2. A photo of a wave breaking over concrete sea steps that ripples in rings around the pointer.
This example failed to draw.
Usage
Put it on img, video. start() registers ripple, 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 ripple<img class="sea-steps" src="/media/portfolio/sea-steps.webp" width="1600" height="1067" data-dio="ripple"/>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.sea-steps', 'ripple', { strength: 1, frequency: 40, speed: 6,})import { start } from '@dioramajs/diorama'import ripple from '@dioramajs/media/ripple'
const app = start()app.attach('.sea-steps', ripple({ strength: 1, frequency: 40, speed: 6,}))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 |
|---|---|---|---|
strengthdata-dio-strength | number0 to 3 | 1 | How far the rings displace the picture. |
frequencydata-dio-frequency | number5 to 100 | 40 | Rings across the image: higher is denser. |
speeddata-dio-speed | number0 to 20 | 6 | How fast the rings travel outwards. |
Inputs and frames
It reads hover, hoverTime, pointer and size
. Draws while the pointer is over it and while hover fades, then stops. While hovered and while the hover fades out; none at rest. 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. Runs with hover held at 0, which shows the image unchanged.
Skipped on touch devices, which never load the engine for it. Off on touch screens, where nothing hovers: the image stays DOM. An entry with `when: "all"` turns it on.
To run it on touch devices too, or to change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { ripple: { when: 'all', reducedMotion: 'off' } } })Cost and quality
- Download
- 0.6 KB min+gzip the first time a page uses it
- GPU
- One textured quad with a few math operations per pixel.
- Memory
- The shared texture of the image.
- Frames
- Idle at rest
It runs from the low tier up. Every tier draws it the same way. The quality plugin picks the tier for each device.
Recipes
A portfolio grid under the pointer
Put ripple on each cover of a project grid. Frames are drawn only while a cover is under the pointer and while its rings settle, so the grid costs nothing while the reader reads the page.
<ul class="works"> <li> <a href="/docs/effects/ripple"> <img src="/media/portfolio/outer-coast.webp" width="1600" height="1067" data-dio="ripple" /> </a> <span>Outer Coast</span> </li> <li> <a href="/docs/effects/ripple"> <img src="/media/portfolio/ice-peak.webp" width="1600" height="1067" data-dio="ripple" /> </a> <span>Geikie Plateau</span> </li> <li> <a href="/docs/effects/ripple"> <img src="/media/portfolio/sea-ice.webp" width="1440" height="960" data-dio="ripple" /> </a> <span>Chukchi Sea</span> </li></ul>Every image of a gallery from code
When the gallery comes from a CMS and you cannot add attributes, attach the effect by selector. The handle it returns changes every image under it at once.
import { start } from '@dioramajs/diorama'
const app = start()const ripples = app.attach('.gallery img', 'ripple', { strength: 1.5 })
// Later, a calmer gallery for the whole page.ripples.params.strength = 0.5A slow swell for a hero
Fewer, slower rings read as a calm sea rather than a splash. Lower frequency and speed and raise strength a little, for a wide image the pointer crosses on its way down the page.
<img src="/img/bay.avif" data-dio="ripple" data-dio-frequency="14" data-dio-speed="2.5" data-dio-strength="1.4"/>Ripple and bend on one image
Both effects share the param strength, so name the effect in the attribute: data-dio-ripple-strength sets only the ripple. The image ripples under the pointer and bows while the page scrolls.
<img src="/img/bay.avif" data-dio="ripple bend" data-dio-ripple-strength="0.8" data-dio-bend-strength="0.6"/>Notes
The rings start where the pointer is and fade with the distance from it, so on a wide image the far side stays nearly still.
Use it on photos. On maps, charts or a picture of text, a moving surface makes the content harder to read while the pointer is over it, which is when the reader looks closest.


