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
fix: bring the Ripple and Floating READMEs in line with the code and trim both pages
matin882110d7b421
diff --git a/animations/07-ambient-background/ambient-ripple/README.md b/animations/07-ambient-background/ambient-ripple/README.mdindex 58fbcb9a..6c4abe94 100644--- a/animations/07-ambient-background/ambient-ripple/README.md+++ b/animations/07-ambient-background/ambient-ripple/README.md@@ -25,7 +25,7 @@ class Ring {update(now) {const progress = (now - this.born) / this.duration; // 0 → 1this.r = MAX_RADIUS * progress;- this.opacity = (1 - progress) * 0.6; // fade out as it expands+ this.opacity = (1 - progress) * 0.5; // fade out as it expands}draw(ctx) {diff --git a/animations/07-ambient-background/ambient-ripple/index.html b/animations/07-ambient-background/ambient-ripple/index.htmlindex 89347fb7..d5b20cd6 100644--- a/animations/07-ambient-background/ambient-ripple/index.html+++ b/animations/07-ambient-background/ambient-ripple/index.html@@ -29,17 +29,9 @@.fg-eyebrow{font-size:11px;font-weight:600;letter-spacing:2px;text-transform:uppercase;color:var(--ui-accent);margin-bottom:8px}.fg-title{font-size:clamp(14px,2vw,18px);font-weight:700;color:#fff;margin-bottom:8px;line-height:1.3}.fg-body{font-size:13px;color:rgba(255,255,255,.72);line-height:1.6}- /* On phones and short screens the stage is small, so the card shrinks and sits lower to leave the rings in view */- @media(max-width:600px),(max-height:760px){- .fg-card{bottom:12px;padding:12px 14px}- .fg-eyebrow{margin-bottom:4px}- .fg-title{margin-bottom:0}- .fg-body{display:none}- }- @media(max-width:600px){- .fg-card{padding:12px}- .fg-title{font-size:13px}- }+ /* On phones and short screens the card shrinks and sits lower, to leave the rings in view */+ @media(max-width:600px),(max-height:760px){.fg-card{bottom:12px;padding:12px 14px}.fg-eyebrow{margin-bottom:4px}.fg-title{margin-bottom:0}.fg-body{display:none}}+ @media(max-width:600px){.fg-card{padding:12px}.fg-title{font-size:13px}}</style><link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3"><script src="../../../assets/js/demo-page.js?v=3" defer></script>@@ -214,8 +206,7 @@// The wait until a source sends its next ring: Time between ripples, up to 40% shorter or longer with Uneven timingfunction gap(){return INTERVAL*1000*(1+(IRR?(Math.random()-.5)*.8:0))}- // The first picture: every source already has three rings on their way, so a stage that is paused on arrival shows the- // effect. Emptying rings first means a resize or a new Number of sources never piles new rings on the old ones.+ // First picture: three rings per source on their way. Emptying rings first keeps a resize or a new Number of sources from piling rings up.function initSources(){rings=[];sources=Array.from({length:SRCS},(_,i)=>({@@ -256,8 +247,7 @@function loop(ts){raf=requestAnimationFrame(loop);if(lastT!==null&&ts-lastT<16)return;- // The first frame after a start has no earlier frame to measure from, so it adds no time; a long gap between- // frames (a background tab) counts for at most 50 ms. Slow motion adds a third of the time.+ // The first frame after a start adds no time, a long gap (a background tab) counts for at most 50 ms, and slow motion adds a thirdconst dt=lastT===null?0:Math.min(ts-lastT,50);lastT=ts;const k=slowTog.checked?1/3:1;@@ -266,17 +256,14 @@}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 rings on screen stay where they are while paused.+ // Top level, so it is there before the shared script (deferred) pauses the loop on arrival under reduced motion. Paused rings stay put.document.addEventListener('hb:pause',e=>{paused=e.detail.paused;if(paused){cancelAnimationFrame(raf);raf=null}else start();});- // Setting the canvas size wipes it, so a real change of the stage's size starts the sources over and draws the first- // picture again 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.+ // A real size change (sizing the canvas wipes it) starts over with the first picture; the same size (a phone's address bar) does nothingfunction resize(){const w=stage.clientWidth,h=stage.clientHeight;if(w===W&&h===H)return;@@ -302,6 +289,7 @@LIFE=+d.life;still();});choices('int-seg',d=>{+ if(+d.secs===INTERVAL)return;INTERVAL=+d.secs;// A source that would wait longer than a new gap sends its next ring within one, so the change shows soonsources.forEach(s=>{s.nextEmit=Math.min(s.nextEmit,clock+Math.random()*gap())});diff --git a/animations/07-ambient-background/floating-elements/README.md b/animations/07-ambient-background/floating-elements/README.mdindex 19c1bc10..a1e91aa9 100644--- a/animations/07-ambient-background/floating-elements/README.md+++ b/animations/07-ambient-background/floating-elements/README.md@@ -18,7 +18,8 @@ function animate(t) {const x = el.bx + Math.sin(el.freq * t + el.phase) * el.amplitude;const y = el.by + Math.cos(el.freq * t * 0.7 + el.phaseY) * el.amplitude * 0.6;- const rot = el.rotation ? el.rotSpeed * t : 0;+ if (el.rotation) el.rot += el.rotSpeed; // its own small turn each frame+ const rot = el.rotation ? el.rot : 0;const opacity = el.pulse? 0.4 + 0.3 * Math.sin(el.pulsePhase + t * 0.5) // stays inside 0.1–0.7: 0.5;@@ -33,20 +34,27 @@ function animate(t) {```jsfunction createShape(count) {- const amp = 30 + Math.random() * 50; // 30–80px drift range- const freq = 0.3 + Math.random() * 0.5; // 0.3–0.8 Hz- const phase = Math.random() * Math.PI * 2; // random start phase- const phaseY = Math.random() * Math.PI * 2; // Y axis out-of-phase+ const amp = RANGE * 0.5 + Math.random() * RANGE * 0.5; // half to all of How far they drift (30, 50 or 90px)+ const freq = 0.3 + Math.random() * 0.5; // its own pace, 0.3 to 0.8 times as fast as t+ const phase = Math.random() * Math.PI * 2; // random start phase+ const phaseY = Math.random() * Math.PI * 2; // Y axis out-of-phase// Y multiplier (0.6) makes motion elliptical rather than circular}```-**CSS shape generation** — shapes without image assets:+**Shape generation** — shapes without image assets, styled in code:-```css-.shape-circle { border-radius: 50%; }-.shape-square { /* default rect */ }-.shape-ring { background: none; border: 2px solid currentColor; border-radius: 50%; }+```js+if (shape === 'ring') {+ el.style.borderRadius = '50%';+ el.style.border = '2px solid ' + color; // outline only+ el.style.background = 'none';+} else if (shape === 'square') {+ el.style.background = color;+} else {+ el.style.borderRadius = '50%'; // circle+ el.style.background = color;+}```**Mouse repulsion** — optional; shapes gently push away from the cursor:@@ -55,7 +63,7 @@ function createShape(count) {if (mouse.x > 0) {const dx = x - mouse.x, dy = y - mouse.y;const d = Math.sqrt(dx*dx + dy*dy);- if (d < 120) {+ if (d > 0 && d < 120) {x += (dx / d) * (120 - d) * 0.08;y += (dy / d) * (120 - d) * 0.08;}diff --git a/animations/07-ambient-background/floating-elements/index.html b/animations/07-ambient-background/floating-elements/index.htmlindex 9aa6b001..eeb7c9ad 100644--- a/animations/07-ambient-background/floating-elements/index.html+++ b/animations/07-ambient-background/floating-elements/index.html@@ -30,13 +30,8 @@.fg-eyebrow{font-size:11px;font-weight:600;letter-spacing:2px;text-transform:uppercase;color:var(--ui-accent);margin-bottom:10px}.fg-title{font-size:clamp(16px,2.2vw,22px);font-weight:700;color:#fff;margin-bottom:10px;line-height:1.2}.fg-body{font-size:13px;color:rgba(255,255,255,.72);line-height:1.6}- /* On phones and short screens the stage is small, so the card shrinks to leave the shapes in view */- @media(max-width:600px),(max-height:760px){- .fg-card{padding:12px 14px}- .fg-eyebrow{margin-bottom:4px}- .fg-title{margin-bottom:0}- .fg-body{display:none}- }+ /* On phones and short screens the card shrinks to leave the shapes in view */+ @media(max-width:600px),(max-height:760px){.fg-card{padding:12px 14px}.fg-eyebrow{margin-bottom:4px}.fg-title{margin-bottom:0}.fg-body{display:none}}</style><link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3"><script src="../../../assets/js/demo-page.js?v=3" defer></script>@@ -227,8 +222,7 @@return{el,bx,by,amp,freq,phase,phaseY,rotSpd,pulsePhs,rot:0};}- // Writes every shape's position, turn and opacity for the current t. It runs on every frame, at the end of rebuild()- // so the shapes are in place at load, and after a setting changes while the loop is paused.+ // Writes each shape's position, turn and opacity for t: every frame, after rebuild(), and after a setting changes while pausedfunction place(){elements.forEach(e=>{let x=e.bx/100*W+Math.sin(e.freq*t+e.phase)*e.amp;@@ -250,8 +244,7 @@place();}- // loop() keeps exactly one frame requested in raf; Pause cancels it and Play starts one loop again.- // Each frame moves t and each shape's turn by a step, or a third of it in slow motion.+ // One pending frame at a time: Pause cancels it, Play starts one loop again. A frame moves t and each turn one step (a third in slow motion).function loop(){raf=requestAnimationFrame(loop);const k=slowTog.checked?1/3:1;@@ -261,16 +254,14 @@}function start(){if(raf)return;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 shapes on screen stay where they are while paused.+ // Top level, so it is there before the shared script (deferred) pauses the loop on arrival under reduced motion. Paused shapes stay put.document.addEventListener('hb:pause',e=>{paused=e.detail.paused;if(paused){cancelAnimationFrame(raf);raf=null}else start();});- // The shapes sit at a share of the stage's size, so a real change of the stage's size places them again 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.+ // A real change of the stage's size places the shapes again, playing or paused; the same size (a phone's address bar) does nothingfunction resize(){const w=stage.clientWidth,h=stage.clientHeight;if(w===W&&h===H)return;@@ -293,8 +284,7 @@}// While paused, a setting that changes how the shapes look places them again so the change showsfunction still(){if(paused)place()}- // The settings that build the shapes do it only when the choice really changes, so pressing the same choice again- // does not scatter a new arrangement+ // The settings that build the shapes ignore a press on the choice already made, so it does not scatter a new arrangementchoices('count-seg',d=>{if(+d.n===COUNT)return;COUNT=+d.n;rebuild()});choices('speed-seg',d=>{SPD=+d.spd;still()});choices('range-seg',d=>{if(+d.px===RANGE)return;RANGE=+d.px;rebuild()});