reflection
A soft reflection on a glossy floor under a product photo, without baking it into the image.
Live preview needs WebGPU or WebGL 2. Three books standing on a pale shelf, each with a soft reflection on the glossy surface below it.
This example failed to draw.
Usage
Put it on img, video. start() registers reflection, 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 reflection<div class="rf-shelf"> <ul class="rf-wall"> <li> <img src="/media/books/blue-shore.webp" width="900" height="1350" data-dio="reflection" data-dio-shadow="0.35" /> </li> <li> <img src="/media/books/low-water.webp" width="900" height="1350" data-dio="reflection" data-dio-shadow="0.35" /> </li> <li> <img src="/media/books/salt-garden.webp" width="900" height="1350" data-dio="reflection" data-dio-shadow="0.35" /> </li> </ul></div>import { start } from '@dioramajs/diorama'
const app = start()app.attach('img', 'reflection', { strength: 0.35, reach: 0.45, blur: 8, gap: 0, trim: true, ripple: 0, shadow: 0.35, fps: 30,})import { start } from '@dioramajs/diorama'import reflection from '@dioramajs/media/reflection'
const app = start()app.attach('img', reflection({ strength: 0.35, reach: 0.45, blur: 8, gap: 0, trim: true, ripple: 0, shadow: 0.35, fps: 30,}))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 1 | 0.35 | Opacity of the reflection at the base: 0 hides it and leaves only the shadow. |
reachdata-dio-reach | number0 to 1 | 0.45 | How far the reflection runs down, as a share of the element's height. |
blurdata-dio-blur | number0 to 40 px | 8 | Blur at the far end of the reflection, growing from sharp at the base: 0 is a mirror.At most low 0 by quality tier. |
gapdata-dio-gap | number-40 to 40 px | 0 | Space between the base and the reflection; negative pulls it up. |
trimdata-dio-trim | boolean | true | Mirror at the lowest solid row of a transparent picture and at the drawn bottom under object-fit; false mirrors at the bottom of the box. |
rippledata-dio-ripple | number0 to 20 px | 0 | Sway of a water ripple in the reflection: 0 is a still floor. |
shadowdata-dio-shadow | number0 to 1 | 0 | Darkness of a soft contact shadow under the base: 0 draws none. |
fpsdata-dio-fps | number1 to 60 | 30 | Frames a second the ripple draws at while visible.At most low 15 by quality tier. |
Inputs and frames
It reads height, size, time and width
. Draws at a steady rate while it is on screen and stops when it leaves. Once when it appears and on layout changes; with a ripple, at most fps a second while visible. 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. The ripple stands still; the reflection itself is not motion.
Runs on every device. The same as on desktop: the reflection does not react to input.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { reflection: { reducedMotion: 'off' } } })Cost and quality
- Download
- 1.9 KB min+gzip the first time a page uses it
- GPU
- Twelve texture reads per pixel of the reflection for the blur and eight for the shadow, only below the image.
- Memory
- The image as a texture; the element itself stays DOM.
- Frames
- Draws while on screen
It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.
| Tier | What changes |
|---|---|
low | No blur, one texture read per pixel of the reflection; the ripple at most 15 frames a second. |
Recipes
A product cutout on a glossy shelf
For e-commerce product shots, a transparent PNG or WebP gets a reflection below it without baking one into the image. Leave room under the image with a margin: the reflection draws below the element’s box and never shifts the layout.
<img src="/shop/speaker.png" data-dio="reflection" data-dio-shadow="0.35" style="margin-bottom: 160px"/>A phone mockup on dark glass
A lower strength, a short reach and a little blur read as dark glass.
<img src="/app/phone.png" data-dio="reflection" data-dio-strength="0.25" data-dio-reach="0.3" data-dio-blur="4"/>A photo over still water
On a full photo the bottom edge is mirrored; ripple adds a gentle wave, as over water.
<img src="/stays/boathouse.avif" data-dio="reflection" data-dio-strength="0.6" data-dio-reach="0.6" data-dio-ripple="6"/>Notes
The reflection takes no clicks and adds nothing to the page layout; give the image room below with a margin. Under reduced motion the ripple stands still.


