Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

ripple

Photo

@dioramajs/media/rippleSource

Rings spread from the pointer while the image is hovered.

View as Markdown
On this page
A wave breaking over concrete steps into the sea

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.

Move the pointer over the photo. The rings follow it and settle once it leaves.
Params of ripple

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.

Terminal window
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.

ParamTypeDefaultDescription
strengthdata-dio-strengthnumber0 to 31How far the rings displace the picture.
frequencydata-dio-frequencynumber5 to 10040Rings across the image: higher is denser.
speeddata-dio-speednumber0 to 206How 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.

  • Outer Coast: a cliff edge over a grey sea Outer Coast
  • Geikie Plateau: a snow peak above a glacier Geikie Plateau
  • Chukchi Sea: floes of sea ice on still water Chukchi Sea

Live preview needs WebGPU or WebGL 2. Three project covers in a row, each rippling while the pointer is over it.

This example failed to draw.

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

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

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