# drops

Water drops on glass over a hero or the whole page: rain that beads and runs, or meltwater left by a thaw.

Drops sit on an invisible pane of glass over the page. Small ones rest as beads; heavy ones run down in fits and starts, wander a little, swallow the beads in their way and leave a wet trail with a few beads behind it, which dries over a few seconds. Each drop catches the light in a bright point near its top, glows faintly along its lower edge and darkens at its rim, like a small lens. In rain motion new drops land all the time. In thaw motion the drops appear behind a front that spreads outwards from a point, as if the glass were melting there, and then run down. Nothing behind the drops is read, so the page stays real and clicks go through.

Module `particles`, category Celebration and particles. Import `@dioramajs/particles/drops`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/particles/src/drops.ts)

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.

```html title="index.html"
<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>
```

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

```html
<header class="hero" data-dio="drops" data-dio-rate="6"><h1>Autumn in the city</h1></header>
```

In page transitions: Fades with the page as it leaves.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `motion` (rebuilds) | `data-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. |
| `trigger` (rebuilds) | `data-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. |
| `fire` | `data-dio-fire` | `number` 0 to 100 | `0` | With trigger manual, every increase plays once more. |
| `rate` | `data-dio-rate` | `number` 0 to 40 | `10` | Rain: new drops a second over the area; 0 lets the drops on the glass dry. At most low 2. |
| `count` | `data-dio-count` | `number` 0 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. |
| `scale` | `data-dio-scale` | `number` 0.4 to 3 | `1` | Size of the drops over their base size. |
| `speed` | `data-dio-speed` | `number` 0 to 3 | `1` | How fast heavy drops run down; 0 keeps every drop where it landed. |
| `trail` | `data-dio-trail` | `number` 0 to 1 | `0.6` | Strength of the wet trail a running drop leaves; 0 leaves none. |
| `dry` | `data-dio-dry` | `number` 0.5 to 20 s | `8` | Seconds a trail takes to dry; beads at rest last about half as long. |
| `lifetime` | `data-dio-lifetime` | `number` 0 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. |
| `merge` | `data-dio-merge` | `boolean` | `true` | Drops that touch run together into one bigger drop. |
| `x` | `data-dio-x` | `number` 0 to 1 | `0.5` | Thaw: where it starts, from the left edge of the area. |
| `y` | `data-dio-y` | `number` 0 to 1 | `0.5` | Thaw: where it starts, from the top edge of the area. |
| `duration` | `data-dio-duration` | `number` 0.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. |
| `color` | `data-dio-color` | `color` | `'#ffffff'` | Color of the light the drops catch along their lower edge. |
| `seed` (rebuilds) | `data-dio-seed` | `number` 1 to 100 | `1` | Where the drops land and how they run. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `motion`: `rain`, `thaw`
- `trigger`: `view`, `manual`

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`presence`](/docs/api/inputs#presence), [`width`](/docs/api/inputs#input-width), [`x`](/docs/api/inputs#input-x), [`y`](/docs/api/inputs#input-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. See [how a frame is decided](/docs/concepts/frames).

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

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

start({ effects: { drops: { reducedMotion: 'static' } } })
```

## Cost and quality

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

- low: At most 240 drops, 70 for a thaw, 2 a second of rain, 30 frames a second.

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

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

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

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

```html
<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" alt="Iced lemonade in a tall glass" />
</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.

## Related

- [confetti](/docs/effects/confetti.md): A burst of confetti from an element, a shower or fireworks to celebrate a sign-up, an order or a donation.
- [emoji](/docs/effects/emoji.md): Emoji or small pictures that float up from a like button, burst out of a success state or rain over a section.
- [snow](/docs/effects/snow.md): Snow, cherry petals or autumn leaves drifting down over a section or the whole page, for a seasonal campaign.
- [sparkles](/docs/effects/sparkles.md): Small twinkling sparkles around a badge, a "new" label, a premium button or a product highlight.
- [assemble](/docs/effects/assemble.md): Thousands of lit particles fly out of the depth around the page and gather into a heading.
- [blobs](/docs/effects/blobs.md): Soft blobs of brand color drifting behind a hero: merging like a lava lamp, as blurred orbs or as glossy glass drops.
- [clouds](/docs/effects/clouds.md): A sky of soft layered clouds for the time of day, daylight, a sunset or a moonlit night, drifting in the wind and parting on scroll.
- [dots](/docs/effects/dots.md): A dot grid behind a hero or in a card that answers the pointer: dots near it grow, move aside or glow, then settle back.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
