176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
feat: Snow / Rain (07.19)
matinb2a541f7d9cf
diff --git a/README.md b/README.mdindex 1941016c..7fa96f2c 100644--- a/README.md+++ b/README.md@@ -238,6 +238,7 @@ All 129 techniques, each linked to its live demo.- **[Matrix Rain](animations/07-ambient-background/matrix-rain/)** — Columns of glowing characters rain down a dark screen. Best for tech themes.- **[Plasma Field](animations/07-ambient-background/plasma/)** — Smooth waves of color flow endlessly, made from math. Best for creative sites.- **[Wave Layers](animations/07-ambient-background/wave-layers/)** — Layers of waves drift sideways, each at its own speed. Best for hero sections and footers.+- **[Snow / Rain](animations/07-ambient-background/snow-rain/)** — Snow drifts down, or rain falls in streaks, over a dark town. Best for seasonal pages.</details>diff --git a/animations/07-ambient-background/README.md b/animations/07-ambient-background/README.mdindex 600b968d..63ff1cd0 100644--- a/animations/07-ambient-background/README.md+++ b/animations/07-ambient-background/README.md@@ -24,6 +24,7 @@ Passive, looping effects that hold visual interest without demanding attention.| [Matrix Rain](matrix-rain/) | Columns of glowing characters rain down a dark screen. Best for tech themes. || [Plasma Field](plasma/) | Smooth waves of color flow endlessly, made from math. Best for creative sites. || [Wave Layers](wave-layers/) | Layers of waves drift sideways, each at its own speed. Best for hero sections and footers. |+| [Snow / Rain](snow-rain/) | Snow drifts down, or rain falls in streaks, over a dark town. Best for seasonal pages. |## The ambient mindsetdiff --git a/animations/07-ambient-background/snow-rain/README.md b/animations/07-ambient-background/snow-rain/README.mdnew file mode 100644index 00000000..78ee8e17--- /dev/null+++ b/animations/07-ambient-background/snow-rain/README.md@@ -0,0 +1,69 @@+# Snow / Rain++## What it is+A snow or rain effect draws falling particles on a see-through canvas laid over a dark scene. Snowflakes fall slowly and sway from side to side, while raindrops fall fast and are drawn as short streaks that lean with the wind. Every particle has a depth, so near ones are bigger, brighter and faster than far ones, which turns a flat sprinkle of dots into weather you look through.++## When to use it+- Winter, holiday and other seasonal campaigns+- Weather apps and forecast headers+- Cozy hero sections for cafés, bookshops, travel or games+- Story and game scenes that need a mood behind the text++## How it works+The town is a still SVG behind the canvas, so the canvas holds only the weather and is cleared and redrawn on every frame. The particles live in three depth layers, far, middle and near, and each layer has its own size, speed, sway or streak length and opacity:++```js+// per 60th of a second: fall speed (vy), sideways speed per unit of wind; r = radius or streak width, a = opacity+const SNOW = [{ r: 1.1, vy: .45, wind: .25, sway: 4, a: .55, share: .4 },+ { r: 1.8, vy: .8, wind: .45, sway: 8, a: .8, share: .35 },+ { r: 2.8, vy: 1.3, wind: .7, sway: 13, a: .95, share: .25 }];+const RAIN = [{ r: .8, vy: 9, wind: 1.2, len: 11, a: .3, share: .4 },+ { r: 1.1, vy: 13, wind: 1.8, len: 16, a: .45, share: .35 },+ { r: 1.6, vy: 18, wind: 2.6, len: 22, a: .62, share: .25 }];+```++Each frame moves every particle by the time that has passed, counted in 60ths of a second (`k`, at most 50 ms, a third of it in slow motion), so the weather falls at the same speed on a 30, 60 or 120 Hz screen. A particle that leaves the bottom starts again just above the top, and one the wind carries out of a side comes back at the other. New particles are spread over the whole width they wrap around in, the stage and 40 pixels on each side, so the wind never leaves an empty band drifting across:++```js+function step(k) {+ for (const { p, list } of groups) for (const q of list) {+ q.y += p.vy * q.sp * k; // q.sp: each particle's own speed, 0.8 to 1.2+ q.x += WIND * p.wind * k;+ q.ph += .02 * q.sp * k; // snow's sway phase+ if (q.y - top > H) Object.assign(q, spawn(-top - Math.random() * (snow ? 20 : H * .3)));+ if (q.x > W + 40) q.x -= W + 80; else if (q.x < -40) q.x += W + 80;+ }+}+```++Drawing puts every particle of a layer into one path, so a frame is three fills for snow or three strokes for rain, however many particles there are. A flake is drawn at `x + sin(phase) × sway`; a drop is a line that leans as far as the drop moves sideways while it falls its own length:++```js+const dx = WIND * p.wind / p.vy * p.len;+for (const q of list) { ctx.moveTo(q.x, q.y); ctx.lineTo(q.x - dx, q.y - p.len); }+ctx.lineWidth = p.r; ctx.stroke();+```++The number of particles follows the area they share, so a phone draws about a quarter of what a laptop draws, and phones and short screens (`(max-width: 600px), (max-height: 500px)`) draw 80% of that again.++## Key parameters+| Parameter | Default | Effect |+|-----------|---------|--------|+| Weather | Snow | Snow drifts down slowly and sways; rain falls more than ten times as fast, drawn as streaks |+| Amount | Medium | How many particles per 100,000 square pixels: light, medium and heavy are 28, 62 and 125 flakes, or 35, 80 and 170 drops; phones draw 80% of that |+| Wind | Gentle | None, gentle or strong: the wind carries snow sideways and tilts the rain, near particles more than far ones |+| Depth | on | Three layers in which near flakes and drops are bigger, brighter and faster than far ones; off, every particle is the size and speed of the middle layer |++## Production notes+- **One path per layer**: setting `fillStyle` and calling `fill()` for each flake costs far more than adding every flake of a layer to one path and filling it once. Group by look, not by particle.+- **Still scene, moving canvas**: the town never changes, so it is an SVG behind the canvas instead of being redrawn every frame.+- **Rain is a streak**: real drops fall several meters a second, so the eye sees lines, not dots. A streak's length and lean come from the drop's own velocity, so the angle always matches the wind.+- **CSS-only snow**: a few dozen flakes can be elements moved with `transform`, but past a hundred or so the page has too many animated layers; a canvas holds thousands.+- **Libraries**: tsParticles has ready snow and rain presets, and Three.js `Points` can do 3D weather with tens of thousands of particles; the depth rule is the same.+- **Reduced motion**: show one still frame, as the demo does, and keep the weather out from behind long text.++## See also+- [Starfield / Space Particles](../starfield/) — particles that stream toward you instead of falling+- [Matrix Rain](../matrix-rain/) — columns of characters that fall and leave trails+- [Wave Layers](../wave-layers/) — the same near-fast, far-slow depth rule with layers of water+- [Particle Constellation](../particle-constellation/) — drifting dots that link up when they come closediff --git a/animations/07-ambient-background/snow-rain/index.html b/animations/07-ambient-background/snow-rain/index.htmlnew file mode 100644index 00000000..ca4475eb--- /dev/null+++ b/animations/07-ambient-background/snow-rain/index.html@@ -0,0 +1,262 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Snow / Rain — Animation Handbook</title>+ <meta name="description" content="Snow drifts down, or rain falls in streaks, over a dark town. Best for seasonal pages.">+ <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/snow-rain/">+ <link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">+ <link rel="icon" type="image/svg+xml" href="../../../favicon.svg">+ <link rel="apple-touch-icon" href="../../../apple-touch-icon.png">+ <meta property="og:type" content="article">+ <meta property="og:site_name" content="Animation Handbook">+ <meta property="og:title" content="Snow / Rain — Animation Handbook">+ <meta property="og:description" content="Snow drifts down, or rain falls in streaks, over a dark town. Best for seasonal pages.">+ <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/snow-rain/">+ <meta property="og:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">+ <meta name="twitter:card" content="summary_large_image">+ <meta name="twitter:title" content="Snow / Rain — Animation Handbook">+ <meta name="twitter:description" content="Snow drifts down, or rain falls in streaks, over a dark town. Best for seasonal pages.">+ <meta name="twitter:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Snow / Rain", "name": "Snow / Rain", "description": "Snow drifts down, or rain falls in streaks, over a dark town. Best for seasonal pages.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/snow-rain/", "inLanguage": "en", "articleSection": "Ambient & Background", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Ambient & Background, Snow / Rain"}</script>+ <style>+ :root{--ui-accent:#ffce5a}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ /* A night sky with the town's warm glow low down; the town is a still picture and the canvas over it holds only the weather */+ .stage{position:relative;overflow:hidden;background:radial-gradient(ellipse 70% 45% at 50% 100%,rgba(255,170,90,.13),transparent),linear-gradient(#03050b,#0a1020 50%,#18223a)}+ .town{position:absolute;left:0;bottom:0;width:100%;height:34%;display:block}+ canvas{position:absolute;inset:0;display:block;width:100%;height:100%}+ </style>+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=6">+ <script src="../../../assets/js/demo-page.js?v=6" defer></script>+</head>+<body class="hb" data-hb-kind="loop">+<nav class="hb-bar" aria-label="Animation Handbook">+ <a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>+ <span class="hb-pager"><a href="../wave-layers/" rel="prev" aria-label="Previous: Wave Layers"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Wave Layers</span></a></span>+</nav>+<main class="hb-page">+ <header class="hb-head">+ <p class="hb-cat">07.19 · Ambient & Background</p>+ <h1>Snow / Rain</h1>+ <p class="hb-lede">Snow drifts down, or rain falls in streaks, over a dark town. Best for seasonal pages.</p>+ </header>++ <section class="hb-step hb-watch" aria-labelledby="hb-watch-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">1</span>+ <div><h2 id="hb-watch-title">Watch it</h2><p>It moves by itself. Pause it to look closely, or turn on slow motion to see each part of the movement.</p></div>+ </div>+ <div class="stage">+ <svg class="town" viewBox="0 0 400 80" preserveAspectRatio="xMidYMax slice" aria-hidden="true">+ <path fill="#0d1424" d="M0 80V44H24V30H40V40H58V22H80V36H96V46H118V18H123V8H125V18H130V34H150V42H176V26H196V38H214V50H236V24H252V36H276V44H300V20H318V40H340V30H362V42H384V34H400V80Z"/>+ <path fill="#f3c26a" fill-opacity=".45" d="M28 36h2v3h-2zM64 28h2v3h-2zM70 40h2v3h-2zM120 24h2v3h-2zM182 32h2v3h-2zM240 30h2v3h-2zM304 26h2v3h-2zM310 36h2v3h-2zM346 36h2v3h-2zM388 40h2v3h-2z"/>+ <path fill="#070a13" d="M0 80V66L13 56L26 66V70H30L36 52L42 70V64L60 50L68 56V52H72V59L78 64V70H84V62L94 54L104 62V70L111 50L118 70V64H150V66L164 54L178 66V70L184 54L190 70L196 56L202 70V62L221 46L228 52V47H232V55L240 62V68H246L253 50L260 68V64L275 52L290 64V70H296V60L313 48L330 60V70L337 52L344 70V64L358 54L372 64V70L378 56L384 70V66L392 58L400 66V80Z"/>+ <path fill="#f3c26a" d="M6 70h3v4h-3zM48 68h3v4h-3zM66 68h3v4h-3zM97 66h3v4h-3zM122 68h3v4h-3zM138 68h3v4h-3zM168 70h3v4h-3zM208 66h3v4h-3zM226 66h3v4h-3zM266 68h3v4h-3zM302 64h3v4h-3zM320 64h3v4h-3zM315 71h3v4h-3zM362 68h3v4h-3zM390 70h3v4h-3z"/>+ </svg>+ <canvas id="cvs" aria-hidden="true"></canvas>+ </div>+ <div class="hb-player">+ <button class="hb-play" type="button" id="btn-pause" data-hb-pause data-state="playing"><svg class="hb-ic hb-i-pause" viewBox="0 0 24 24" aria-hidden="true"><rect x="6" y="4" width="4" height="16" rx="1"/><rect x="14" y="4" width="4" height="16" rx="1"/></svg><svg class="hb-ic hb-i-play" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 3l14 9-14 9z"/></svg><span class="hb-pause-label">Pause</span></button>+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo autocomplete="off"><span>Slow motion</span></label>+ </div>+ </section>++ <section class="hb-step hb-try" aria-labelledby="hb-try-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">2</span>+ <div><h2 id="hb-try-title">Try it</h2><p>Change a setting and see the difference as it moves.</p></div>+ </div>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="mode-lbl">Weather</p>+ <div class="seg" id="mode-seg" role="group" aria-labelledby="mode-lbl">+ <button type="button" data-mode="snow" class="on" aria-pressed="true">Snow</button>+ <button type="button" data-mode="rain" aria-pressed="false">Rain</button>+ </div>+ <p class="hb-hint">Snow drifts and sways; rain falls fast in streaks.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="amount-lbl">Amount</p>+ <div class="seg" id="amount-seg" role="group" aria-labelledby="amount-lbl">+ <button type="button" data-amount="light" aria-pressed="false">Light</button>+ <button type="button" data-amount="medium" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-amount="heavy" aria-pressed="false">Heavy</button>+ </div>+ <p class="hb-hint">How many flakes or drops fall; phones draw fewer.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="wind-lbl">Wind</p>+ <div class="seg" id="wind-seg" role="group" aria-labelledby="wind-lbl">+ <button type="button" data-wind="0" aria-pressed="false">None</button>+ <button type="button" data-wind="1" class="on" aria-pressed="true">Gentle</button>+ <button type="button" data-wind="2.6" aria-pressed="false">Strong</button>+ </div>+ <p class="hb-hint">Wind carries snow sideways and tilts the rain.</p>+ </div>+ </div>+ <details class="hb-options">+ <summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>+ <div class="hb-settings">+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Depth</span><input class="hb-switch" type="checkbox" role="switch" id="depth-tog" checked autocomplete="off"></label>+ <p class="hb-hint">Near flakes and drops are bigger, brighter and faster than far ones.</p>+ </div>+ </div>+ </details>+ </section>++ <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">3</span>+ <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>+ </div>+ <div class="hb-card">+ <p class="hb-prompt">Add falling snow or rain to [the dark section you want it over]. Lay a see-through canvas over the section and draw small particles on it, moving each one down on every frame by the time that has passed, and start it again at the top once it leaves the bottom. Snowflakes fall slowly and sway from side to side; raindrops fall fast and are drawn as short streaks that lean with the wind. Give every particle a depth, so near ones are bigger, brighter and faster than far ones. Draw fewer particles on phones. If the visitor has reduced motion turned on, show one still frame. Match the settings listed below.</p>+ <div class="hb-chips-box" hidden>+ <p class="hb-chips-title">Your settings</p>+ <ul class="hb-chips"></ul>+ </div>+ <div class="hb-copy-row">+ <button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>+ <p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p>+ </div>+ </div>+ </section>++ <section class="hb-about" aria-labelledby="hb-what-title">+ <div class="hb-what">+ <h2 id="hb-what-title">What it is</h2>+ <div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>+ </div>+ <div class="hb-fit">+ <h2>Good for</h2>+ <ul class="hb-tags hb-good"><li>Winter and holiday pages</li><li>Weather apps</li><li>Cozy hero sections</li><li>Story and game scenes</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Light pages</li><li>Long reading pages</li></ul>+ </div>+ </section>++ <section class="hb-related" aria-labelledby="hb-related-title" hidden>+ <h2 id="hb-related-title">Similar animations</h2>+ <div class="hb-rel-list"></div>+ </section>+</main>+<footer class="hb-foot"><span>Animation Handbook</span><a href="#top">Back to top ↑</a></footer>+<script>+ const cvs=document.getElementById('cvs'),ctx=cvs.getContext('2d');+ const stage=document.querySelector('.stage');+ const slowTog=document.getElementById('slow-tog');+ const phone=matchMedia('(max-width:600px),(max-height:500px)'); // phones and short screens draw fewer particles+ const FRAME=1000/60; // one step is what a 60 Hz frame adds, so a faster screen or a slow frame does not change the speed+ // Far, middle and near layers. Per 60th of a second: fall speed (vy) and sideways speed per unit of wind; snow sways by up+ // to sway pixels, rain is a streak len pixels long. r is a flake's radius or a streak's width, a its opacity, share its part.+ const SNOW=[{r:1.1,vy:.45,wind:.25,sway:4,a:.55,share:.4},{r:1.8,vy:.8,wind:.45,sway:8,a:.8,share:.35},{r:2.8,vy:1.3,wind:.7,sway:13,a:.95,share:.25}];+ const RAIN=[{r:.8,vy:9,wind:1.2,len:11,a:.3,share:.4},{r:1.1,vy:13,wind:1.8,len:16,a:.45,share:.35},{r:1.6,vy:18,wind:2.6,len:22,a:.62,share:.25}];+ const DENSITY={snow:{light:28,medium:62,heavy:125},rain:{light:35,medium:80,heavy:170}}; // per 100,000 square pixels+ let W=0,H=0,raf=null,lastT=null;+ let MODE='snow',AMOUNT='medium',WIND=1,DEPTH=true;+ let groups=[]; // one per layer: its settings (p) and its particles (list)++ // x spans the whole width a particle can wrap around in (the stage and 40 pixels on each side), so the wind, which shifts+ // every particle the same way, leaves no empty band drifting across the stage+ function spawn(y){return {x:Math.random()*(W+80)-40,y,ph:Math.random()*6.283,sp:.8+Math.random()*.4};}+ // The count follows the area the particles share (the stage and its two side bands), so a phone draws about a quarter of a+ // laptop's, and phones and short screens draw 80% of that again. A layer that stays the same keeps its particles, so a new+ // amount only adds or removes some; fresh deals them all again, spread over the stage.+ function build(fresh){+ const L=MODE==='snow'?SNOW:RAIN,layers=DEPTH?L:[L[1]];+ const n=DENSITY[MODE][AMOUNT]*(W+80)*H/1e5*(phone.matches?.8:1);+ groups=layers.map((p,i)=>{+ const list=!fresh&&groups[i]&&groups[i].p===p?groups[i].list:[],want=Math.round(n*(DEPTH?p.share:1));+ list.length=Math.min(list.length,want);+ while(list.length<want)list.push(spawn(Math.random()*H));+ return {p,list};+ });+ }++ // k is how many 60 Hz frames this step stands for (a third of that in slow motion). A particle that falls out of the+ // bottom starts again just above the top, and one that the wind carries out of a side comes back in at the other.+ function step(k){+ for(const {p,list} of groups){+ const top=MODE==='snow'?p.r:p.len;+ for(const q of list){+ q.y+=p.vy*q.sp*k;q.x+=WIND*p.wind*k;q.ph+=.02*q.sp*k;+ if(q.y-top>H){Object.assign(q,spawn(-top-Math.random()*(MODE==='snow'?20:H*.3)));}+ if(q.x>W+40)q.x-=W+80;else if(q.x<-40)q.x+=W+80;+ }+ }+ }+ // Every particle of a layer goes into one path, so each frame is three fills (snow) or three strokes (rain).+ function draw(){+ ctx.clearRect(0,0,W,H);+ for(const {p,list} of groups){+ ctx.beginPath();+ if(MODE==='snow'){+ for(const q of list){const x=q.x+Math.sin(q.ph)*p.sway;ctx.moveTo(x+p.r,q.y);ctx.arc(x,q.y,p.r,0,6.283);}+ ctx.fillStyle='rgba(255,255,255,'+p.a+')';ctx.fill();+ }else{+ const dx=WIND*p.wind/p.vy*p.len; // the streak leans as far as the drop moves sideways while it falls its length+ for(const q of list){ctx.moveTo(q.x,q.y);ctx.lineTo(q.x-dx,q.y-p.len);}+ ctx.strokeStyle='rgba(175,200,235,'+p.a+')';ctx.lineWidth=p.r;ctx.stroke();+ }+ }+ }++ // loop() keeps exactly one frame requested in raf; Pause cancels it and Play starts one loop again. A step is the time since+ // the last frame in 60ths of a second, never more than 50 ms (a background tab does not leap), a third of it in slow motion;+ // the first frame after a start has nothing to measure from and adds none.+ function loop(ts){+ raf=requestAnimationFrame(loop);+ const dt=lastT===null?0:Math.min(ts-lastT,50);+ lastT=ts;+ step(dt/FRAME*(slowTog.checked?1/3:1));+ draw();+ }+ function start(){if(raf)return;lastT=null;raf=requestAnimationFrame(loop);}++ // Registered at the top level, before the shared script (deferred) can run: under reduced motion it pauses the loop on+ // arrival, which this listener must catch. The weather on screen stays as it is while paused.+ document.addEventListener('hb:pause',e=>{+ if(e.detail.paused){cancelAnimationFrame(raf);raf=null;}+ else start();+ });+ // A tab that comes back after being hidden has no earlier frame to measure from, so its first frame adds no step+ document.addEventListener('visibilitychange',()=>{lastT=null;});++ // Setting the canvas size wipes it, so a real change of the stage's size deals the particles again and draws them at once,+ // playing or paused. A resize that leaves the stage as it was (a phone's address bar sliding in or out) does nothing.+ function resize(){+ const w=stage.clientWidth,h=stage.clientHeight;+ if(w===W&&h===H)return;+ W=w;H=h;+ const dpr=Math.min(window.devicePixelRatio||1,2);+ cvs.width=Math.round(W*dpr);cvs.height=Math.round(H*dpr);ctx.setTransform(dpr,0,0,dpr,0,0);+ build(true);draw();+ }++ function choices(id,pick){+ const buttons=document.querySelectorAll('#'+id+' button');+ buttons.forEach(b=>b.addEventListener('click',()=>{+ if(b.classList.contains('on'))return; // pressing the choice already made does nothing+ buttons.forEach(x=>{x.classList.toggle('on',x===b);x.setAttribute('aria-pressed',String(x===b))});+ pick(b.dataset);+ }));+ }+ // Every change draws at once, so it shows while paused too. Wind redraws the rain's slant; snow shows it once it moves.+ choices('mode-seg',d=>{MODE=d.mode;build(true);draw();});+ choices('amount-seg',d=>{AMOUNT=d.amount;build(false);draw();});+ choices('wind-seg',d=>{WIND=+d.wind;draw();});+ document.getElementById('depth-tog').addEventListener('change',e=>{DEPTH=e.target.checked;build(true);draw();});++ resize();+ window.addEventListener('resize',resize);+ // A window that crosses the phone size changes how many particles it draws, even when the stage keeps its size+ function onPhone(){build(false);draw();}+ if(phone.addEventListener)phone.addEventListener('change',onPhone);+ else if(phone.addListener)phone.addListener(onPhone);+ start();+</script>+</body>+</html>diff --git a/animations/07-ambient-background/wave-layers/index.html b/animations/07-ambient-background/wave-layers/index.htmlindex 306ae230..6c578310 100644--- a/animations/07-ambient-background/wave-layers/index.html+++ b/animations/07-ambient-background/wave-layers/index.html@@ -57,7 +57,7 @@<body class="hb" data-hb-kind="loop"><nav class="hb-bar" aria-label="Animation Handbook"><a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>- <span class="hb-pager"><a href="../plasma/" rel="prev" aria-label="Previous: Plasma Field"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Plasma Field</span></a></span>+ <span class="hb-pager"><a href="../plasma/" rel="prev" aria-label="Previous: Plasma Field"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Plasma Field</span></a><a href="../snow-rain/" rel="next" aria-label="Next: Snow / Rain"><span><span class="hb-dir">Next: </span>Snow / Rain</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span></nav><main class="hb-page"><header class="hb-head">diff --git a/index.html b/index.htmlindex e9b0c8ea..0c81ead1 100644--- a/index.html+++ b/index.html@@ -826,6 +826,15 @@ button,input{font:inherit;color:inherit}.pv-wavelayers .l2{top:56cqh;color:#123f5a;animation-duration:9.5s;animation-delay:-4s}.pv-wavelayers .l2 svg{height:10cqh}.pv-wavelayers .l3{top:71cqh;color:#08263b;animation-duration:7s;animation-delay:-2s}.pv-wavelayers .l3 svg{height:13cqh}@keyframes d-wl{to{transform:translateX(-50%)}}+/* Snow / Rain: two layers of flakes, tiled every 60 or 90 pixels, fall exactly one tile per cycle, so the loop has no seam; the+ near layer is bigger and faster and sways on the way down; a dark row of roofs with lit windows stands in front */+.pv-snowrain{background:radial-gradient(ellipse 70% 45% at 50% 100%,rgba(255,170,90,.13),transparent),linear-gradient(#03050b,#0a1020 50%,#18223a);overflow:hidden}+.pv-snowrain .sn{position:absolute;left:-10%;right:-10%;top:-60px;bottom:0;background:radial-gradient(circle at 20% 30%,rgba(255,255,255,.7) 1.1px,transparent 1.7px),radial-gradient(circle at 72% 62%,rgba(255,255,255,.55) 1px,transparent 1.6px),radial-gradient(circle at 44% 88%,rgba(255,255,255,.65) 1.1px,transparent 1.7px);background-size:60px 60px;animation:d-sn 6s linear infinite}+.pv-snowrain .s2{top:-90px;background:radial-gradient(circle at 28% 22%,#fff 2px,transparent 2.6px),radial-gradient(circle at 78% 70%,rgba(255,255,255,.9) 1.7px,transparent 2.3px);background-size:90px 90px;animation:d-sn2 4.2s linear infinite}+.pv-snowrain .town{position:absolute;left:0;right:0;bottom:0;height:24%;background:linear-gradient(#f3c26a 0 0) 12% 80%/4px 5px no-repeat,linear-gradient(#f3c26a 0 0) 38% 84%/4px 5px no-repeat,linear-gradient(#f3c26a 0 0) 63% 78%/4px 5px no-repeat,linear-gradient(#f3c26a 0 0) 86% 82%/4px 5px no-repeat,#070a13;+ clip-path:polygon(0 100%,0 52%,9% 30%,18% 52%,22% 52%,27% 18%,32% 52%,36% 52%,46% 26%,56% 52%,59% 52%,64% 22%,69% 52%,72% 52%,82% 30%,92% 52%,95% 52%,98% 34%,100% 44%,100% 100%)}+@keyframes d-sn{to{transform:translateY(60px)}}+@keyframes d-sn2{50%{transform:translate(5px,45px)}100%{transform:translate(0,90px)}}/* ── bespoke: added demos ── */.pv-magnet{background:#08090c;display:grid;place-items:center;position:relative}@@ -1017,7 +1026,7 @@ button,input{font:inherit;color:inherit}<section class="wrap home-hero" aria-labelledby="hero-title"><span class="float fl1" aria-hidden="true"></span><span class="float fl2" aria-hidden="true"></span><span class="float fl3" aria-hidden="true"></span><span class="float fl4" aria-hidden="true"></span><span class="float fl5" aria-hidden="true"></span><span class="float fl6" aria-hidden="true"></span>- <p class="pill"><span class="pill-dot" aria-hidden="true"></span>130 free animations · no coding needed</p>+ <p class="pill"><span class="pill-dot" aria-hidden="true"></span>131 free animations · no coding needed</p><h1 class="h1" id="hero-title">What do you want to animate?</h1><p class="sub">Pick a place, or describe it in your own words. Every animation plays live, and each one comes with a ready-made prompt for your AI assistant.</p><form class="search" id="search-form" role="search" action="./" method="get">@@ -1074,8 +1083,8 @@ button,input{font:inherit;color:inherit}<p class="empty-s">Try a simpler word, or pick one of these:</p><p class="pop"><button type="button" data-q="fade in">fade in</button><button type="button" data-q="typing text">typing text</button><button type="button" data-q="loading spinner">loading spinner</button><button type="button" data-q="parallax">parallax</button><button type="button" data-q="confetti">confetti</button></p></div>- <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 130 animations</span><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M6 13l6 6 6-6"/></svg></button></div>- <noscript><p class="noscript">This page shows its animations with JavaScript. All 130 are still easy to reach: see the <a href="https://github.com/matinmonshizadeh/animation-handbook#categories">category list on GitHub</a> or the <a href="sitemap.xml">full sitemap</a>. Each demo is a page of its own under <code>/animations/<category>/<name>/</code>.</p></noscript>+ <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 131 animations</span><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M6 13l6 6 6-6"/></svg></button></div>+ <noscript><p class="noscript">This page shows its animations with JavaScript. All 131 are still easy to reach: see the <a href="https://github.com/matinmonshizadeh/animation-handbook#categories">category list on GitHub</a> or the <a href="sitemap.xml">full sitemap</a>. Each demo is a page of its own under <code>/animations/<category>/<name>/</code>.</p></noscript></section><section class="how" id="how" aria-labelledby="how-title">@@ -1093,7 +1102,7 @@ button,input{font:inherit;color:inherit}<footer class="wrap foot"><a class="brand" href="./"><svg class="mark" viewBox="0 0 32 32" aria-hidden="true"><circle class="ring" cx="11.16" cy="20.84" r="6.1"/><circle class="ring" cx="15.12" cy="16.88" r="6.1"/><circle class="ring" cx="18.51" cy="13.49" r="6.1"/><circle class="ball" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>- <p class="foot-t">130 web animations with live demos and copyable prompts.</p>+ <p class="foot-t">131 web animations with live demos and copyable prompts.</p><nav class="nav" aria-label="Footer"><a class="lnk" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener noreferrer">GitHub</a><a class="lnk" href="#top">Back to top</a></nav></footer><div class="toast" id="toast" role="status" aria-live="polite"><span class="ok" aria-hidden="true"><svg class="i" viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span><span class="toast-t"></span></div>@@ -1286,6 +1295,7 @@ const CATS=[['matrix-rain','Matrix Rain','Columns of glowing characters rain down a dark screen. Best for tech themes.'],['plasma','Plasma Field','Smooth waves of color flow endlessly, made from math. Best for creative sites.'],['wave-layers','Wave Layers','Layers of waves drift sideways, each at its own speed. Best for hero sections and footers.'],+ ['snow-rain','Snow / Rain','Snow drifts down, or rain falls in streaks, over a dark town. Best for seasonal pages.'],]}];@@ -1296,7 +1306,7 @@ const PV={'hamburger-menu-toggle':'hamb','theme-toggle-morph':'thememorph','copy-to-clipboard':'copyfx','star-rating':'stars','toast-notification':'toast','segmented-control':'segct','pull-to-refresh':'pullref','flip-card-3d':'flip3d','matrix-rain':'matrix','plasma':'plasmapv',- 'wave-layers':'wavelayers',+ 'wave-layers':'wavelayers','snow-rain':'snowrain','parallax-depth-of-field':'dof','parallax-scrolling':'plx','reverse-scrolling-columns':'revcol','cover-card-to-fixed-header':'cover','fly-in-fly-out-contact-list':'flylist','stacking-cards':'stack','scroll-trigger':'trigger','scrub-animation':'scrub','pin-animation':'pin','snap-scrolling':'snap',@@ -1469,7 +1479,8 @@ const PLACES={'synthwave-grid':['bg'],'matrix-rain':['bg'],'plasma':['bg'],- 'wave-layers':['bg','intro']+ 'wave-layers':['bg','intro'],+ 'snow-rain':['bg']};// The eight cards of "Good places to start", in this order.const PICKS=['click-ripple','typewriter-effect','flip-card-3d','aurora','hamburger-menu-toggle','loading-spinner','parallax-scrolling','slide-up-reveal'];@@ -1485,6 +1496,7 @@ function pvMarkup(k){case 'sig7': return '<span class="s7 anim"></span>';case 'wavelayers': {let d='M0 0C18 0 32 40 50 40';for(let s=1;s<16;s++)d+='S'+(s*50+32)+(s%2?' 0 ':' 40 ')+(s*50+50)+(s%2?' 0':' 40');return [800,600,400].map((w,k)=>'<span class="wl l'+(k+1)+' anim"><svg viewBox="0 0 '+w+' 40" preserveAspectRatio="none"><path d="'+d+'V40H0Z"/></svg><i></i></span>').join('');}+ case 'snowrain': return '<span class="sn anim"></span><span class="sn s2 anim"></span><span class="town"></span>';case 'aurora': return '<span class="band b1 anim"></span><span class="band b2 anim"></span><span class="band b3 anim"></span>';case 'mesh': return '<span class="m m1 anim"></span><span class="m m2 anim"></span><span class="m m3 anim"></span>';case 'glow': return '<span class="core anim"></span><span class="ring anim"></span>';diff --git a/sitemap.xml b/sitemap.xmlindex 3607264b..8f85acce 100644--- a/sitemap.xml+++ b/sitemap.xml@@ -131,4 +131,5 @@<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/matrix-rain/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/plasma/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/wave-layers/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>+ <url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/snow-rain/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url></urlset>