drops
Water drops on glass over a hero or the whole page: rain that beads and runs, or meltwater left by a thaw.
Late October, Lisbon
Rain on the window, coffee on the table
A café guide for wet afternoons: twelve places with big windows and a seat by the glass.
Read the guideLive preview needs WebGPU or WebGL 2. A café guide hero behind a rainy window; drops land on the glass, run down in fits and starts and leave wet trails that dry.
This example failed to draw.
Usage
Put it on any element, such as a hero or a banner, or <body> for the whole viewport; it is never hidden. start() registers drops, 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 drops<section class="dr-hero" data-dio="drops" data-dio-count="120" data-dio-color="#ffcf9a"> <p class="dr-kicker">Late October, Lisbon</p> <h2>Rain on the window, coffee on the table</h2> <p class="dr-copy">A café guide for wet afternoons: twelve places with big windows and a seat by the glass.</p> <a class="dr-cta" href="/guides/rainy-day" >Read the guide</a></section>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.dr-hero', 'drops', { motion: 'rain', trigger: 'view', fire: 0, rate: 10, count: 120, scale: 1, speed: 1, trail: 0.6, dry: 8, lifetime: 0, merge: true, x: 0.5, y: 0.5, duration: 2.4, color: '#ffcf9a',})import { start } from '@dioramajs/diorama'import drops from '@dioramajs/particles/drops'
const app = start()app.attach('.dr-hero', drops({ motion: 'rain', trigger: 'view', fire: 0, rate: 10, count: 120, scale: 1, speed: 1, trail: 0.6, dry: 8, lifetime: 0, merge: true, x: 0.5, y: 0.5, duration: 2.4, color: '#ffcf9a',}))Page transitions
Fades with the page as it leaves. 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 |
|---|---|---|---|
motionrebuildsdata-dio-motion | 'rain' | 'thaw' | 'rain' | rain: drops land all over the area at rate a second; thaw: count drops appear behind a front that spreads from x, y over duration, like meltwater. |
triggerrebuildsdata-dio-trigger | 'view' | 'manual' | 'view' | view: the first time the element is on screen a thaw plays, or rain lands count drops at once and keeps falling while it is on screen; manual: each increase of fire plays a thaw, or a shower of count drops. |
firedata-dio-fire | number0 to 100 | 0 | With trigger manual, every increase plays once more. |
ratedata-dio-rate | number0 to 40 | 10 | Rain: new drops a second over the area; 0 lets the drops on the glass dry.At most low 2 by quality tier. |
countdata-dio-count | number0 to 400 | 140 | Drops a thaw leaves behind its front, or rain lands at once when it starts and on each fire.At most low 70 by quality tier. |
scaledata-dio-scale | number0.4 to 3 | 1 | Size of the drops over their base size. |
speeddata-dio-speed | number0 to 3 | 1 | How fast heavy drops run down; 0 keeps every drop where it landed. |
traildata-dio-trail | number0 to 1 | 0.6 | Strength of the wet trail a running drop leaves; 0 leaves none. |
drydata-dio-dry | number0.5 to 20 s | 8 | Seconds a trail takes to dry; beads at rest last about half as long. |
lifetimedata-dio-lifetime | number0 to 30 s | 0 | Seconds a drop lasts at most, running or at rest, fading out over the last third of them; 0 lets drops dry or run off on their own. |
mergedata-dio-merge | boolean | true | Drops that touch run together into one bigger drop. |
xdata-dio-x | number0 to 1 | 0.5 | Thaw: where it starts, from the left edge of the area. |
ydata-dio-y | number0 to 1 | 0.5 | Thaw: where it starts, from the top edge of the area. |
durationdata-dio-duration | number0.3 to 10 s | 2.4 | Thaw: seconds the front takes to cross the area. The same as frost’s duration, the drops follow its thaw. |
colordata-dio-color | color | '#ffffff' | Color of the light the drops catch along their lower edge. |
seedrebuildsdata-dio-seed | number1 to 100 | 1 | Where the drops land and how they run. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
It reads delta, height, presence, width, x and y
. Draws at a steady rate while it is on screen and stops when it leaves. Every frame while drops run or a thaw spreads, 15 a second while only beads and trails dry, none once the glass is dry. Rain draws as long as it falls. How a frame is decided.
Reduced motion and touch
With reduced motion it is off and the element shows as plain HTML. Off: neither the module nor the engine loads for it, and the page is unchanged.
Runs on every device. Nothing to touch: drops ignore the pointer, and scrolling works as usual.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { drops: { reducedMotion: 'static' } } })Cost and quality
- Download
- 4.4 KB min+gzip the first time a page uses it
- GPU
- Two instanced draws of small quads, drops and trail pieces; nothing full screen.
- Memory
- Instance buffers for 480 drops and 1600 trail pieces, about 54 KB.
- 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 | At most 240 drops, 70 for a thaw, 2 a second of rain, 30 frames a second. |
Recipes
A frozen page that thaws
Put frost and drops on one fixed element over the page. Raise the frost’s cover to freeze the window; lower it and fire the drops with the same point and duration, and the meltwater appears behind the thaw front and runs down the glass.
<div class="window" data-dio="frost drops" data-dio-frost-cover="0" data-dio-drops-motion="thaw" data-dio-drops-trigger="manual" style="position: fixed; inset: 0; pointer-events: none"></div>const pane = document.querySelector('.window')// Freeze.pane.dataset.dioFrostCover = '1'// Thaw from a point, 30% from the left and 60% from the top.for (const effect of ['frost', 'drops']) { pane.setAttribute(`data-dio-${effect}-x`, '0.3') pane.setAttribute(`data-dio-${effect}-y`, '0.6')}pane.dataset.dioFrostCover = '0'pane.dataset.dioDropsFire = String(Number(pane.dataset.dioDropsFire ?? 0) + 1)Condensation on a cold drink
speed="0" keeps every drop where it landed and rate="0" stops new ones, so the glass is beaded once and the beads evaporate slowly.
<figure class="drink" data-dio="drops" data-dio-rate="0" data-dio-count="160" data-dio-speed="0" data-dio-dry="12"> <img src="/menu/lemonade.avif" /></figure>Notes
Nothing behind the drops is read: each drop is drawn as a small lens, darker at its top and lit at its bottom, with a crisp rim and one highlight, so it looks like water over any page. The element is never hidden, and clicks go through.
Small drops rest and evaporate after a while; heavy ones run, faster as they grow, swallow the beads in their way and leave a thin trail that dries over dry seconds. After a thaw the glass ends clean.
Frames are drawn while drops run or a thaw spreads, at 15 a second while only beads and trails dry, and none once the glass is dry. On the low tier there are fewer drops at 30 frames a second. Under reduced motion it does not load at all.
motion, trigger and seed rebuild the effect; the other params change live.