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: Liquid Glass (06.24): nothing stays stretched or moving when reduced motion turns on mid-move, a resize keeps the run's path, a note where the glass is frosted, and the colors in variables
matinfc2189e4e5dd
diff --git a/animations/06-3d-advanced/liquid-glass/README.md b/animations/06-3d-advanced/liquid-glass/README.mdindex a87a27a9..6e036e30 100644--- a/animations/06-3d-advanced/liquid-glass/README.md+++ b/animations/06-3d-advanced/liquid-glass/README.md@@ -37,7 +37,7 @@ d[k + 1] = 128 - 127 * (ny * m + z * Y / hh) / (1 + MAG); // grThe filter shifts a pixel by up to half its `scale`, so How much it bends only changes `scale` (twice the bend times the rim's width, times 1.15 for the pull toward the middle); the map is drawn again only when the panel changes size or shape.-**Which browsers bend.** Chromium-based browsers, such as Chrome, Edge and Opera, draw an SVG filter in `backdrop-filter` (the demo was checked in Chrome and Edge). Safari and Firefox do not draw it, and a feature test cannot tell: `CSS.supports()` checks only that the rule is valid, not that the bend appears. The demo gives the bend to browsers that list Chromium among their brands in `navigator.userAgentData`, which only Chromium-based browsers have, and shows everyone else frosted glass: a blur of the backdrop with the same tint, rim and shadow, and a glow inside the rim that grows with How much it bends.+**Which browsers bend.** Chromium-based browsers, such as Chrome, Edge and Opera, draw an SVG filter in `backdrop-filter` (the demo was checked in Chrome and Edge). Safari and Firefox do not draw it, and a feature test cannot tell: `CSS.supports()` checks only that the rule is valid, not that the bend appears. The demo gives the bend to browsers that list Chromium among their brands in `navigator.userAgentData`, which only Chromium-based browsers have, and shows everyone else frosted glass: a blur of the backdrop with the same tint, rim and shadow, and a glow inside the rim that grows with How much it bends. There the help line above the stage adds that this browser shows the frosted version. `navigator.userAgentData` exists only on secure pages (https, or localhost), so Chrome opening the page over plain http at a network address gets the frosted glass too.```jsconst REFRACT = !!(navigator.userAgentData && navigator.userAgentData.brands.some(b => b.brand === 'Chromium'))@@ -55,9 +55,9 @@ for (acc += dt * f; acc >= FRAME; acc -= FRAME) { // f is 1/glass.style.transform = `translate(${x - gw / 2}px, ${y - gh / 2}px) matrix(${1 + a}, ${b}, ${b}, ${1 - a}, 0, 0)`;```-Show me glides along three legs (to the left end, across to the right end and back where it started), each eased in and out and timed by its length, 3.6 s in all. The arrow keys move a target a step at a time (8% of the stage's shorter side, three steps with Shift), and the panel glides toward it by a share of the gap per 1/60 s, the same on any screen.+Show me glides along three legs (to the left end, across to the right end and back where it started), each eased in and out and timed by its length, 3.6 s in all. When the stage changes size (a resize, or a phone turned sideways), the glass, the end of a glide, every point of a run and the place a held Show me returns to keep their shares of the stage; one that was at the rest place goes to the new rest place. The arrow keys move a target a step at a time (8% of the stage's shorter side, three steps with Shift), and the panel glides toward it by a share of the gap per 1/60 s, the same on any screen.-**Reduced motion.** The panel still follows the pointer or finger while it is dragged, but it never stretches, wobbles or glides: the arrow keys, a tap and Reset move it at once, and Show me puts it at the right end for 1.2 s and back.+**Reduced motion.** The panel still follows the pointer or finger while it is dragged, but it never stretches, wobbles or glides: the arrow keys, a tap and Reset move it at once, and Show me puts it at the right end for 1.2 s and back. Every frame under reduced motion sets the stretch and its speed to zero, and turning reduced motion on while the glass moves stops a run where it is and ends a glide at its target, so nothing is left stretched or moving.## Key parameters| Parameter | Default | Effect |diff --git a/animations/06-3d-advanced/liquid-glass/index.html b/animations/06-3d-advanced/liquid-glass/index.htmlindex 07f6b30f..bbb4740d 100644--- a/animations/06-3d-advanced/liquid-glass/index.html+++ b/animations/06-3d-advanced/liquid-glass/index.html@@ -24,32 +24,34 @@:root{--ui-accent:#3fd6c4}*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}/* The picture behind the glass, drawn with gradients and sized by the stage (1cqw and 1cqh are 1% of its width and height):- dots, stripes, thin neon lines and big letters give the bend edges to show */- .stage{--lg-tint:#f4f4f2;--lg-tp:9%;--lg-blur:0px;--lg-fb:3px;--lg-rim:23px;position:relative;overflow:hidden;container-type:size;-webkit-user-select:none;user-select:none;- background:radial-gradient(80% 90% at 88% 4%,#3b2c86,transparent 62%),linear-gradient(168deg,#1e1752,#100f36 52%,#0a1b2d)}- .lg-scene,.lg-scene>*{position:absolute;display:block}- .lg-scene{inset:0}- .lg-dots{left:0;top:0;width:58%;height:70%;background:radial-gradient(circle,rgba(255,255,255,.32) 1.5px,transparent 2px) 0 0/18px 18px;-webkit-mask:radial-gradient(farthest-side at 0 0,#000 50%,transparent);mask:radial-gradient(farthest-side at 0 0,#000 50%,transparent)}- .lg-sun{right:6%;top:7%;width:min(42cqh,27cqw);aspect-ratio:1;border-radius:50%;background:linear-gradient(#ffd36e,#ff8a5c 55%,#ff5c8a);-webkit-mask:linear-gradient(#000 50%,transparent 0),repeating-linear-gradient(transparent 0 2.5%,#000 0 9%);mask:linear-gradient(#000 50%,transparent 0),repeating-linear-gradient(transparent 0 2.5%,#000 0 9%)}+ dots, stripes, thin neon lines and big letters give the bend edges to show. Its colors, and the glass's, are set here;+ --lg-m is the stop of the masks, where only its alpha counts. */+ .stage{--lg-glow:#3b2c86;--lg-sky:#1e1752;--lg-sky-2:#100f36;--lg-deep:#0a1b2d;--lg-dot:rgba(255,255,255,.32);--lg-sun:#ffd36e;--lg-sun-2:#ff8a5c;--lg-sun-3:#ff5c8a;+ --lg-neon:#b98cff;--lg-tower:#2c2070;--lg-tower-2:#150f3c;--lg-sea:#3fd6c4;--lg-ball:#ff6f8b;--lg-ball-2:#ffce5a;--lg-ink:#fff;--lg-light:255,255,255;--lg-shade:0,0,0;--lg-m:#000;+ --lg-tint:#f4f4f2;--lg-tp:9%;--lg-blur:0px;--lg-fb:3px;--lg-rim:23px;position:relative;overflow:hidden;container-type:size;-webkit-user-select:none;user-select:none;+ background:radial-gradient(80% 90% at 88% 4%,var(--lg-glow),transparent 62%),linear-gradient(168deg,var(--lg-sky),var(--lg-sky-2) 52%,var(--lg-deep))}+ .lg-scene,.lg-scene>*{position:absolute;display:block}.lg-scene{inset:0}+ .lg-dots{left:0;top:0;width:58%;height:70%;background:radial-gradient(circle,var(--lg-dot) 1.5px,transparent 2px) 0 0/18px 18px;-webkit-mask:radial-gradient(farthest-side at 0 0,var(--lg-m) 50%,transparent);mask:radial-gradient(farthest-side at 0 0,var(--lg-m) 50%,transparent)}+ .lg-sun{right:6%;top:7%;width:min(42cqh,27cqw);aspect-ratio:1;border-radius:50%;background:linear-gradient(var(--lg-sun),var(--lg-sun-2) 55%,var(--lg-sun-3));-webkit-mask:linear-gradient(var(--lg-m) 50%,transparent 0),repeating-linear-gradient(transparent 0 2.5%,var(--lg-m) 0 9%);mask:linear-gradient(var(--lg-m) 50%,transparent 0),repeating-linear-gradient(transparent 0 2.5%,var(--lg-m) 0 9%)}/* A skyline of dark towers lined with neon, cut out of one wide band */- .lg-city{left:0;right:0;bottom:30%;height:26%;background:repeating-linear-gradient(90deg,#b98cff 0 2px,transparent 2px 9px),linear-gradient(#2c2070,#150f3c);clip-path:polygon(0 100%,0 52%,6% 52%,6% 30%,11% 30%,11% 64%,15% 64%,15% 12%,21% 12%,21% 44%,26% 44%,26% 70%,31% 70%,31% 26%,36% 26%,36% 56%,41% 56%,41% 6%,46% 6%,46% 40%,52% 40%,52% 62%,57% 62%,57% 20%,62% 20%,62% 48%,67% 48%,67% 34%,72% 34%,72% 66%,77% 66%,77% 24%,83% 24%,83% 54%,88% 54%,88% 16%,94% 16%,94% 46%,100% 46%,100% 100%)}- .lg-sea{left:0;right:0;bottom:0;height:30%;background:repeating-linear-gradient(#3fd6c4 0 4px,transparent 4px 13px);-webkit-mask:linear-gradient(transparent,#000 25%);mask:linear-gradient(transparent,#000 25%)}+ .lg-city{left:0;right:0;bottom:30%;height:26%;background:repeating-linear-gradient(90deg,var(--lg-neon) 0 2px,transparent 2px 9px),linear-gradient(var(--lg-tower),var(--lg-tower-2));clip-path:polygon(0 100%,0 52%,6% 52%,6% 30%,11% 30%,11% 64%,15% 64%,15% 12%,21% 12%,21% 44%,26% 44%,26% 70%,31% 70%,31% 26%,36% 26%,36% 56%,41% 56%,41% 6%,46% 6%,46% 40%,52% 40%,52% 62%,57% 62%,57% 20%,62% 20%,62% 48%,67% 48%,67% 34%,72% 34%,72% 66%,77% 66%,77% 24%,83% 24%,83% 54%,88% 54%,88% 16%,94% 16%,94% 46%,100% 46%,100% 100%)}+ .lg-sea{left:0;right:0;bottom:0;height:30%;background:repeating-linear-gradient(var(--lg-sea) 0 4px,transparent 4px 13px);-webkit-mask:linear-gradient(transparent,var(--lg-m) 25%);mask:linear-gradient(transparent,var(--lg-m) 25%)}.lg-ball{width:7cqmin;aspect-ratio:1;border-radius:50%}- .lg-b1{left:47%;top:11%;background:#ff6f8b}.lg-b2{left:30%;top:20%;width:4cqmin;background:#ffce5a}- .lg-word{left:5%;top:27%;font-weight:900;font-size:min(17cqh,10cqw);line-height:1;letter-spacing:-.03em;color:#fff;white-space:nowrap}+ .lg-b1{left:47%;top:11%;background:var(--lg-ball)}.lg-b2{left:30%;top:20%;width:4cqmin;background:var(--lg-ball-2)}+ .lg-word{left:5%;top:27%;font-weight:900;font-size:min(17cqh,10cqw);line-height:1;letter-spacing:-.03em;color:var(--lg-ink);white-space:nowrap}/* Narrow stages (phones): a smaller sun, higher, so the letters pass under it */@container (aspect-ratio < 1.8){.lg-sun{top:5%;width:26cqw}.lg-word{top:34%}.lg-b1{left:56%;top:6%}}/* The glass: a faint tint, a gloss at the top, a thin rim that catches the light and a shadow below. Where the bend cannot bedrawn, the backdrop is blurred (frosted glass) and a glow inside the rim grows with the bend. */.lg-glass{position:absolute;left:0;top:0;cursor:grab;touch-action:none;will-change:transform;- background:radial-gradient(120% 80% at 25% 0%,rgba(255,255,255,.16),transparent 55%),color-mix(in srgb,var(--lg-tint) var(--lg-tp),transparent);- -webkit-backdrop-filter:blur(var(--lg-fb)) saturate(1.7);backdrop-filter:blur(var(--lg-fb)) saturate(1.7);box-shadow:0 18px 38px rgba(0,0,0,.45),0 3px 8px rgba(0,0,0,.25),inset 0 0 var(--lg-rim) calc(var(--lg-rim) / 3) rgba(255,255,255,.3)}- .lg-refract .lg-glass{backdrop-filter:url(#lg-filter) blur(var(--lg-blur)) saturate(1.3);box-shadow:0 18px 38px rgba(0,0,0,.45),0 3px 8px rgba(0,0,0,.25),inset 0 0 14px rgba(255,255,255,.12),inset 0 -10px 16px -12px rgba(255,255,255,.45)}+ background:radial-gradient(120% 80% at 25% 0%,rgba(var(--lg-light),.16),transparent 55%),color-mix(in srgb,var(--lg-tint) var(--lg-tp),transparent);+ -webkit-backdrop-filter:blur(var(--lg-fb)) saturate(1.7);backdrop-filter:blur(var(--lg-fb)) saturate(1.7);box-shadow:0 18px 38px rgba(var(--lg-shade),.45),0 3px 8px rgba(var(--lg-shade),.25),inset 0 0 var(--lg-rim) calc(var(--lg-rim) / 3) rgba(var(--lg-light),.3)}+ .lg-refract .lg-glass{backdrop-filter:url(#lg-filter) blur(var(--lg-blur)) saturate(1.3);box-shadow:0 18px 38px rgba(var(--lg-shade),.45),0 3px 8px rgba(var(--lg-shade),.25),inset 0 0 14px rgba(var(--lg-light),.12),inset 0 -10px 16px -12px rgba(var(--lg-light),.45)}.lg-glass::before,.lg-map{content:"";position:absolute;inset:0;border-radius:inherit;pointer-events:none}- .lg-glass::before{padding:1.5px;background:linear-gradient(135deg,#fff,rgba(255,255,255,.2) 28%,rgba(255,255,255,.06) 55%,rgba(255,255,255,.62));-webkit-mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);-webkit-mask-composite:xor;mask-composite:exclude}- .lg-map{background:0 0/100% 100% no-repeat;opacity:.92}- .lg-glass.lg-grab{cursor:grabbing}- .lg-defs{position:absolute;width:0;height:0;overflow:hidden}+ .lg-glass::before{padding:1.5px;background:linear-gradient(135deg,rgb(var(--lg-light)),rgba(var(--lg-light),.2) 28%,rgba(var(--lg-light),.06) 55%,rgba(var(--lg-light),.62));-webkit-mask:linear-gradient(var(--lg-m) 0 0) content-box,linear-gradient(var(--lg-m) 0 0);-webkit-mask-composite:xor;mask-composite:exclude}+ .lg-map{background:0 0/100% 100% no-repeat;opacity:.92}.lg-glass.lg-grab{cursor:grabbing}.lg-defs{position:absolute;width:0;height:0;overflow:hidden}+ /* Where the glass is frosted, the help line above has one more line: on a laptop the stage gives it back, so the player bar stays on the first screen */+ @media(min-width:1025px){.hb-page .stage.lg-frost{--hb-stage-h:clamp(300px,calc(100vh - 444px),440px)}}@media(min-width:1025px) and (max-height:760px){.hb-page .stage.lg-frost{--hb-stage-h:clamp(260px,calc(100vh - 354px),440px)}}</style><link rel="stylesheet" href="../../../assets/css/demo-page.css?v=6"><script src="../../../assets/js/demo-page.js?v=6" defer></script>@@ -69,7 +71,7 @@<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">Drag it</h2><p>Drag the glass or tap where it should go, use the arrow keys, or press Show me.</p></div>+ <div><h2 id="hb-watch-title">Drag it</h2><p>Drag the glass or tap where it should go, use the arrow keys, or press Show me.<span id="lg-note" hidden> This browser shows the frosted version; the bend shows in Chrome and Edge.</span></p></div></div><div class="stage" id="stage"><div class="lg-scene" aria-hidden="true"><i class="lg-dots"></i><i class="lg-sun"></i><i class="lg-city"></i><i class="lg-sea"></i><i class="lg-ball lg-b1"></i><i class="lg-ball lg-b2"></i><p class="lg-word">Look closer</p></div>@@ -184,7 +186,7 @@ const slowTog=document.getElementById('slow-tog'),vars=stage.style,reduce=matchM// Chromium draws an SVG filter in backdrop-filter; Safari and Firefox do not, and CSS.supports() only checks the syntax, so the// bend goes to browsers that name Chromium among their brands and the others keep the frosted glass.const REFRACT=!!(navigator.userAgentData&&navigator.userAgentData.brands.some(b=>b.brand==='Chromium'))&&CSS.supports('backdrop-filter','url(#lg-filter)');-stage.classList.toggle('lg-refract',REFRACT);+stage.classList.toggle('lg-refract',REFRACT);stage.classList.toggle('lg-frost',!REFRACT);document.getElementById('lg-note').hidden=REFRACT;const FRAME=1000/60,RUN_MS=3600,EMAX=.12,MAG=.15;// Each shape: its width and height as shares of the base width, and its corner radius as a share of its heightconst SHAPES={card:[1,.62,.34],pill:[1.12,.42,.5],circle:[.68,.68,.5]};@@ -214,14 +216,16 @@ function setBend(){fDisp.setAttribute('scale',(2*bend*Math.min(gw,gh)*.35*(1+MAGconst cx=v=>Math.min(W-gw/2,Math.max(gw/2,v)),cy=v=>Math.min(H-gh/2,Math.max(gh/2,v));const home=()=>[cx(W*.56),cy(H*.86-gh/2)]; // its lower edge over the sea, so the rim bends the stripesfunction place(){glass.style.transform=`translate(${(x-gw/2).toFixed(2)}px,${(y-gh/2).toFixed(2)}px) matrix(${(1+a).toFixed(4)},${b.toFixed(4)},${b.toFixed(4)},${(1-a).toFixed(4)},0,0)`;}-// The glass is a share of the stage's width (150 to 280px wide for a card), never more than 55% of its height. A new size keeps-// the glass where it was, as a share of the stage, and draws the map again.+// The glass is a share of the stage's width (150 to 280px wide for a card), at most 55% of its height. A new size draws the map+// again and keeps each place the glass is at or heading for (run, glide, held Show me) at its share; its rest place stays home.function layout(){const w=stage.clientWidth,h=stage.clientHeight;if(!w||!h)return;const [sw,sh,sr]=SHAPES[shape],base=Math.min(280,Math.max(150,w*.3)),k=Math.min(1,h*.55/(base*sh)),nw=Math.round(base*sw*k),nh=Math.round(base*sh*k);- const first=!W;if(W){x*=w/W;y*=h/H;}W=w;H=h;+ const first=!W,old=W&&home(),kx=W?w/W:1,ky=H?h/H:1;W=w;H=h;+ const fit=p=>p&&(old&&Math.abs(p[0]-old[0])+Math.abs(p[1]-old[1])<1?home():[cx(p[0]*kx),cy(p[1]*ky)]);if(nw!==gw||nh!==gh){gw=nw;gh=nh;glass.style.width=gw+'px';glass.style.height=gh+'px';glass.style.borderRadius=Math.round(gh*sr)+'px';drawMap();}- if(first)[x,y]=home();lx=x=cx(x);ly=y=cy(y);place();+ if(first)[x,y]=home();else{[x,y]=fit([x,y]);target=fit(target);holdFrom=fit(holdFrom);if(run)for(const l of run.legs){l[0]=fit(l[0]);l[1]=fit(l[1]);}}+ lx=x;ly=y;place();}// One loop, only while something moves. Show me and a glide move the glass in the demo's own time (a third of it in slow motion);@@ -230,6 +234,8 @@ function layout(){function wake(){if(!raf){lastT=null;lx=x;ly=y;raf=requestAnimationFrame(tick);}}function tick(ts){raf=0;const dt=lastT===null?0:Math.min(ts-lastT,50),f=slowTog.checked?1/3:1,ox=lx,oy=ly;lastT=ts;+ // Reduced motion (even turned on mid-move): a run stops where it is, a glide ends at its target, nothing stretches+ if(reduce.matches){if(target)[x,y]=target;run=target=null;a=b=va=vb=vx=vy=acc=0;}if(run){run.t+=dt*f;const p=along(run);x=cx(p[0]);y=cy(p[1]);if(run.t>=run.end)run=null;}else if(target){const k=1-Math.pow(.8,dt*f/FRAME);x+=(target[0]-x)*k;y+=(target[1]-y)*k;if(Math.abs(target[0]-x)+Math.abs(target[1]-y)<.5){[x,y]=target;target=null;}}@@ -268,15 +274,14 @@ glass.addEventListener('keydown',e=>{// Show me: the glass glides to the left end, across to the right end and back in 3.6 s. Under reduced motion it jumps to the// right end, stays 1.2 s and jumps back. A second press starts again from where the first one began.-function stopHold(){clearTimeout(hold);hold=0;}// The visitor pressed, typed, scrolled, touched or tabbed into the stage: a run stops where it is and the glass settles there-function stopRun(){if(hold)stopHold();if(run){run=null;wake();}}+function stopHold(){clearTimeout(hold);hold=0;}function stopRun(){if(hold)stopHold();if(run){run=null;wake();}}document.addEventListener('hb:input',stopRun);stage.addEventListener('focusin',e=>{if(e.isTrusted)stopRun();});document.getElementById('btn-demo').addEventListener('click',()=>{if(hold){stopHold();[x,y]=holdFrom;}const p=run?run.legs[2][1]:[x,y],l=[cx(0),cy(H*.4)],r=[cx(W),cy(H*.46)];drag=null;target=null;glass.classList.remove('lg-grab');- if(reduce.matches){holdFrom=p;[x,y]=r;place();hold=setTimeout(()=>{hold=0;[x,y]=p;place();},1200);return;}+ if(reduce.matches){holdFrom=p;[x,y]=r;place();hold=setTimeout(()=>{hold=0;[x,y]=holdFrom;place();},1200);return;}const pts=[[x,y],l,r,p],len=[0,1,2].map(i=>Math.hypot(pts[i+1][0]-pts[i][0],pts[i+1][1]-pts[i][1])),L=len[0]+len[1]+len[2]||1;const legs=[0,1,2].map(i=>[pts[i],pts[i+1],Math.max(1,RUN_MS*len[i]/L)]);run={t:0,legs,end:legs[0][2]+legs[1][2]+legs[2][2]};wake();