# snow

Snow, cherry petals or autumn leaves drifting down over a section or the whole page, for a seasonal campaign.

Soft round flakes fall at different depths: far ones small, slow and faint, near ones larger, faster and softer, as if out of focus. They sway as they fall, drift with the wind and move aside around the pointer. The petals style lets pink petals tumble and flip on their way down, and leaves turns them into pointed autumn leaves with a darker midrib. With pile set, a soft drift of snow builds up along the bottom edge and the flakes settle into it. Everything draws over the page and clicks go through to it.

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

A winter sale banner for an outdoor store with snow falling over it and a soft drift building along its bottom edge.

```html title="index.html"
<section class="sn-sale" data-dio="snow" data-dio-pile="26" data-dio-count="180">
  <p class="sn-kicker">Winter sale, until January 6</p>
  <h2>30% off down jackets and wool layers</h2>
  <p class="sn-copy">Free returns until the end of February, and free shipping on orders over $80.</p>
  <a class="sn-cta" href="/sale">Shop the sale</a>
</section>
```

## Usage

Put it on: any element, such as a hero or a banner, or <body> for the whole page; it is never hidden.

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

```html
<section class="sale" data-dio="snow" data-dio-pile="24"><h2>Winter sale: 30% off outerwear</h2><a href="/sale">Shop the sale</a></section>
```

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

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'snow' \| 'petals' \| 'leaves'` | `'snow'` | snow drops soft round flakes; petals tumble pink petals; leaves drops autumn leaves. |
| `count` | `data-dio-count` | `number` 0 to 1500 | `160` | Flakes over the element or the viewport. At most low 70, medium 110. |
| `scale` | `data-dio-scale` | `number` 0.3 to 3 | `1` | Size of the flakes over their base size. |
| `speed` | `data-dio-speed` | `number` 0 to 3 | `1` | How fast the flakes fall; 0 holds them in the air. |
| `wind` | `data-dio-wind` | `number` -2 to 2 | `0.2` | Sideways drift: positive to the right, negative to the left. |
| `color` (rebuilds) | `data-dio-color` | `string` | `''` | Colors of the flakes, any CSS colors separated by spaces; empty uses the style’s own. |
| `pile` | `data-dio-pile` | `number` 0 to 80 px | `0` | Height of the drift that builds up at the bottom edge, snow only; 0 for none. |
| `push` | `data-dio-push` | `number` 0 to 1 | `0.5` | How far the pointer pushes nearby flakes aside; 0 leaves them alone. |
| `fps` | `data-dio-fps` | `number` 0 to 60 | `30` | Most frames a second the snowfall draws; 0 holds it still. At most low 24. |
| `seed` (rebuilds) | `data-dio-seed` | `number` 1 to 100 | `1` | Positions, sizes and colors of the flakes. |

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

### Variants

- `style`: `snow`, `petals`, `leaves`
  - `snow` drops soft round flakes.
  - `petals` tumble pink petals.
  - `leaves` drops autumn leaves.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`hover`](/docs/api/inputs#hover), [`pointerWorld`](/docs/api/inputs#pointerWorld), [`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. Up to fps frames a second while the element is on screen, none off screen or at fps 0; the pointer draws at full rate while it pushes. 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. Flakes move aside from a finger on the element; scrolling works as usual.

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

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

## Cost and quality

Loads 2.8 KB the first time a page uses it. GPU: One instanced draw of small quads over the element or the viewport. Memory: Three instance buffers of 1501 entries, about 72 KB.

- low: At most 70 flakes and 24 frames a second.
- medium: At most 110 flakes.

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

## Recipes

### Snow over the whole page for the holidays

Put the effect on `<body>` and the snow falls over the viewport on every page, over the content, and never blocks a click. Keep `count` modest on a page people read, and turn it off after the campaign by removing one attribute.

```html
<body
  data-dio="snow"
  data-dio-count="120"
  data-dio-wind="-0.3"
>
  <main>…</main>
</body>
```

### Cherry petals for a spring collection

`style="petals"` lets pink petals tumble and flip on their way down, for spring launches, weddings and spas. A little `wind` carries them across.

Pink petals tumbling over a pale green header for a spring clothing collection.

```html title="index.html"
<header class="sn-spring" data-dio="snow" data-dio-style="petals" data-dio-count="70" data-dio-wind="0.6">
  <h2>The spring collection is here</h2>
  <p>Linen dresses, light knits and sandals for warmer days.</p>
</header>
```

### Autumn leaves in brand colors

`style="leaves"` drops pointed leaves with a darker midrib. Pass your own colors to `color`, `var()` included, to match a seasonal menu or a sale.

```html
<section
  class="autumn"
  data-dio="snow"
  data-dio-style="leaves"
  data-dio-color="#c2410c #f59e0b var(--brand)"
>
  <h2>The autumn menu</h2>
</section>
```

## Notes

The flakes draw over everything in the element’s box, or over the viewport on `<body>`, and the element itself is never hidden or changed, so links and buttons under the snow keep working.

Far flakes are small, slow and faint and near ones larger, faster and softer, so the snowfall has depth. With `pile` the drift starts low and builds up over half a minute while the element is on screen; it is drawn for the snow style only.

It draws up to `fps` frames a second while the element is on screen and none off screen; on the low tier at most 70 flakes at 24 frames a second. Under reduced motion it does not load at all.

`style`, `color` and `seed` rebuild the effect when they change. The count, size, speed, wind, drift and push 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.
- [drops](/docs/effects/drops.md): Water drops on glass over a hero or the whole page: rain that beads and runs, or meltwater left by a thaw.
- [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.
- [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)
