# ripple

Rings spread from the pointer while the image is hovered.

The picture ripples like water around the pointer: round rings whose crests catch a little light, calm right under the pointer. The rings fade out with the distance and settle when the pointer leaves, so at rest the copy matches the image.

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

A photo of a wave breaking over concrete sea steps that ripples in rings around the pointer.

```html title="index.html"
<img class="sea-steps" src="/media/portfolio/sea-steps.webp" alt="A wave breaking over concrete steps into the sea" width="1600" height="1067" data-dio="ripple" />
```

## Usage

Put it on: img, video.

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

```html
<img src="/photo.avif" alt="" data-dio="ripple" />
```

In page transitions: Fades with the page transition.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `strength` | `data-dio-strength` | `number` 0 to 3 | `1` | How far the rings displace the picture. |
| `frequency` | `data-dio-frequency` | `number` 5 to 100 | `40` | Rings across the image: higher is denser. |
| `speed` | `data-dio-speed` | `number` 0 to 20 | `6` | How fast the rings travel outwards. |

## Inputs and frames

Reads [`hover`](/docs/api/inputs#hover), [`hoverTime`](/docs/api/inputs#hoverTime), [`pointer`](/docs/api/inputs#pointer), [`size`](/docs/api/inputs#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. 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. 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.

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

start({ effects: { ripple: { when: 'all', reducedMotion: 'off' } } })
```

## Cost and quality

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

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

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

Three project covers in a row, each rippling while the pointer is over it.

```html title="index.html"
<ul class="works">
  <li>
    <a href="/docs/effects/ripple"><img src="/media/portfolio/outer-coast.webp" alt="Outer Coast: a cliff edge over a grey sea" 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" alt="Geikie Plateau: a snow peak above a glacier" 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" alt="Chukchi Sea: floes of sea ice on still water" width="1440" height="960" data-dio="ripple" /></a>
    <span>Chukchi Sea</span>
  </li>
</ul>
```

```ts title="script.ts"
// The links of the example go nowhere: a click would only jump the page.
export default function mount(example: HTMLElement): () => void {
  const stop = (e: Event) => e.preventDefault()
  const links = [...example.querySelectorAll('.works a')]
  for (const a of links) a.addEventListener('click', stop)
  return () => {
    for (const a of links) a.removeEventListener('click', stop)
  }
}
```

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

```ts
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.5
```

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

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

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

## 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.
- [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.
- [Performance and quality](/docs/guides/performance.md)
