snow
Snow, cherry petals or autumn leaves drifting down over a section or the whole page, for a seasonal campaign.
Winter sale, until January 6
30% off down jackets and wool layers
Free returns until the end of February, and free shipping on orders over $80.
Shop the saleLive preview needs WebGPU or WebGL 2. A winter sale banner for an outdoor store with snow falling over it and a soft drift building along its bottom edge.
This example failed to draw.
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. 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 snow<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>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.sn-sale', 'snow', { style: 'snow', count: 180, scale: 1, speed: 1, wind: 0.2, pile: 26, push: 0.5, fps: 30,})import { start } from '@dioramajs/diorama'import snow from '@dioramajs/particles/snow'
const app = start()app.attach('.sn-sale', snow({ style: 'snow', count: 180, scale: 1, speed: 1, wind: 0.2, pile: 26, push: 0.5, fps: 30,}))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 |
|---|---|---|---|
stylerebuildsdata-dio-style | 'snow' | 'petals' | 'leaves' | 'snow' |
|
countdata-dio-count | number0 to 1500 | 160 | Flakes over the element or the viewport.At most low 70, medium 110 by quality tier. |
scaledata-dio-scale | number0.3 to 3 | 1 | Size of the flakes over their base size. |
speeddata-dio-speed | number0 to 3 | 1 | How fast the flakes fall; 0 holds them in the air. |
winddata-dio-wind | number-2 to 2 | 0.2 | Sideways drift: positive to the right, negative to the left. |
colorrebuildsdata-dio-color | string | '' | Colors of the flakes, any CSS colors separated by spaces; empty uses the style’s own. |
piledata-dio-pile | number0 to 80 px | 0 | Height of the drift that builds up at the bottom edge, snow only; 0 for none. |
pushdata-dio-push | number0 to 1 | 0.5 | How far the pointer pushes nearby flakes aside; 0 leaves them alone. |
fpsdata-dio-fps | number0 to 60 | 30 | Most frames a second the snowfall draws; 0 holds it still.At most low 24 by quality tier. |
seedrebuildsdata-dio-seed | number1 to 100 | 1 | Positions, sizes and colors of the flakes. |
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, hover, pointerWorld, presence, width, x and 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. 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. Flakes move aside from a finger on the element; scrolling works as usual.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { snow: { reducedMotion: 'static' } } })Cost and quality
- Download
- 2.8 KB min+gzip 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.
- 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 70 flakes and 24 frames a second. |
medium | At most 110 flakes. |
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.
<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.
The spring collection is here
Linen dresses, light knits and sandals for warmer days.
Live preview needs WebGPU or WebGL 2. Pink petals tumbling over a pale green header for a spring clothing collection.
This example failed to draw.
<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.
<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.