Skip to content

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.

feat: Liquid Glass shows its bend map on the glass's left half, arrows to what each spot shows and a dashed line where the rim begins (See inside) and Plain glass beside Liquid glass (Compare)

matin2a6c1c7bc887
diff --git a/animations/06-3d-advanced/liquid-glass/index.html b/animations/06-3d-advanced/liquid-glass/index.html
index 99e6a6ff..aa200796 100644
--- a/animations/06-3d-advanced/liquid-glass/index.html
+++ b/animations/06-3d-advanced/liquid-glass/index.html
@@ -23,13 +23,14 @@
<style>
: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):
+ /* The picture behind the glass, drawn with gradients and sized by its box, the whole stage outside Compare (1cqw and 1cqh are 1%
+ of its width and height):
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;--lg-vh:1vh;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-bg: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));background:var(--lg-bg)}
.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%)}
@@ -50,6 +51,33 @@
.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,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}
+ /* See inside and Compare. The scene and the glass sit in one box, which fills the stage and lays out as before in Normal.
+ See inside draws on the glass, so it all moves and stretches with it: the bend map on its left half, arrows from spots
+ across it to where each reads the picture from, and a dashed line where the rim begins. Compare sets an inert copy of the
+ box beside it (stacked on phones), whose glass has the same tint, rim, shadow and Frost but no bend. The captions lie
+ under the glass, so they never cover it. */
+ .lg-box{position:absolute;inset:0;container-type:size}
+ .lg-twin,.lg-key,.lg-half,.lg-x,.lg-mh{display:none}
+ .lg-cap{padding:2px 7px;border-radius:5px;background:rgba(12,10,36,.9);color:#f4f4f2;font:600 12px/1.2 var(--hb-font);white-space:nowrap}
+ /* The key, at the top left: on a phone its three rows end above the place Show me's glide reaches at its left end */
+ .lg-key{position:absolute;left:6px;top:6px;right:6px;flex-wrap:wrap;align-items:flex-start;gap:3px 6px}
+ .lg-half{position:absolute;left:8px;top:8px}
+ .lg-x{position:absolute;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none;fill:none;stroke-linecap:round;stroke-linejoin:round}
+ .lg-x .lg-u{stroke:rgba(12,10,36,.75);stroke-width:3.5}.lg-x rect{stroke-dasharray:5 4}.lg-rim{stroke:rgba(255,255,255,.85);stroke-width:1.5}.lg-arr{stroke:#fff;stroke-width:1.5}
+ .stage[data-hb-mode="inside"] .lg-key{display:flex}
+ .stage[data-hb-mode="inside"] .lg-x{display:block}
+ /* The map's left half (a second map, as the switch's is hidden); with the switch on, the switch's map covers the whole glass */
+ .stage[data-hb-mode="inside"] .lg-mh{display:block;clip-path:inset(0 50% 0 0)}
+ .stage[data-hb-mode="inside"] .lg-map:not([hidden])+.lg-mh{display:none}
+ .lg-refract .lg-glass.lg-plain{backdrop-filter:blur(var(--lg-blur)) saturate(1.3)}
+ .stage[data-hb-mode="compare"]{background:#2a2a30}
+ .stage[data-hb-mode="compare"] .lg-box{overflow:hidden;background:var(--lg-bg)}
+ .stage[data-hb-mode="compare"] .lg-box:not(.lg-twin){left:calc(50% + 1px)}
+ .stage[data-hb-mode="compare"] .lg-twin{display:block;right:calc(50% + 1px)}
+ .stage[data-hb-mode="compare"] .lg-half{display:block}
+ /* Phones: the halves stacked, each name at its bottom left, where Show me's glide never passes */
+ @media(max-width:600px){.stage[data-hb-mode="compare"] .lg-box:not(.lg-twin){left:0;top:calc(50% + 1px)}
+ .stage[data-hb-mode="compare"] .lg-twin{right:0;bottom:calc(50% + 1px)}.stage[data-hb-mode="compare"] .lg-half{top:auto;bottom:6px}}
/* Where the glass is frosted the help line above has one more line, so from 601px wide (where the shared heights apply) the stage
gives it back, down to the shared 260px, and the player bar stays where it is in Chrome. --lg-vh: the small viewport height where known */
@supports(height:1svh){.stage{--lg-vh:1svh}}@media(min-width:601px){.hb-page .stage.lg-frost{--hb-stage-h:clamp(300px,calc(100 * var(--lg-vh) - 444px),440px)}}@media(min-width:601px) and (max-height:760px){.hb-page .stage.lg-frost{--hb-stage-h:clamp(260px,calc(100 * var(--lg-vh) - 354px),440px)}}
@@ -75,9 +103,18 @@
<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.<span id="lg-note" hidden> Frosted here: the bend shows in Chrome or Edge on a computer or Android.</span></p></div>
</div>
+ <div class="seg hb-modes" role="group" aria-label="What the box shows" data-hb-modes>
+ <button type="button" data-hb-mode="normal" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-hb-mode="inside" aria-pressed="false">See inside</button>
+ <button type="button" data-hb-mode="compare" aria-pressed="false">Compare</button>
+ </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>
- <div class="lg-glass" id="glass" tabindex="0" role="group" aria-roledescription="glass panel" aria-label="Glass over a colorful picture. Drag it, or press the arrow keys to move it."><i class="lg-map" id="lg-map" hidden></i></div>
+ <div class="lg-box" id="lg-box">
+ <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>
+ <div class="lg-key" aria-hidden="true"><span class="lg-cap" data-hb-caption>Bend map: red sideways, green up and down</span><span class="lg-cap" data-hb-caption>Arrows point to what each spot shows</span><span class="lg-cap" data-hb-caption>Inside the dashed line it barely bends</span></div>
+ <p class="lg-cap lg-half" aria-hidden="true" data-hb-caption>Liquid glass</p>
+ <div class="lg-glass" id="glass" tabindex="0" role="group" aria-roledescription="glass panel" aria-label="Glass over a colorful picture. Drag it, or press the arrow keys to move it."><i class="lg-map" id="lg-map" hidden></i><i class="lg-map lg-mh"></i><svg class="lg-x" aria-hidden="true" focusable="false"><rect class="lg-u"/><rect class="lg-rim"/><path class="lg-u"/><path class="lg-arr"/></svg></div>
+ </div>
<svg class="lg-defs" aria-hidden="true" focusable="false"><filter id="lg-filter" filterUnits="userSpaceOnUse" x="0" y="0" width="1" height="1" color-interpolation-filters="sRGB"><feImage id="lg-img" x="0" y="0" width="1" height="1" preserveAspectRatio="none" result="map"/><feDisplacementMap id="lg-disp" in="SourceGraphic" in2="map" scale="0" xChannelSelector="R" yChannelSelector="G"/></filter></svg>
</div>
<div class="hb-player">
@@ -85,6 +122,10 @@
<button class="hb-play" type="button" id="btn-reset" data-hb-reset><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>Reset</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>
+ <div class="hb-mode-notes" aria-live="polite">
+ <p data-hb-for="inside" hidden>Inside, a bend map steers the glass (left half: red sideways, green up and down); each arrow points to what its spot shows, so the rim magnifies most.</p>
+ <p data-hb-for="compare" hidden>Plain glass tints the picture without bending it; Liquid glass also reads the picture from further in near its rim, so its edge bends and magnifies. Drag Liquid glass or press Show me.</p>
+ </div>
</section>
<section class="hb-step hb-try" aria-labelledby="hb-try-title">
@@ -183,7 +224,7 @@
</main>
<footer class="hb-foot"><span>Animation Handbook</span><a href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener">Source on GitHub</a><a href="#top">Back to top ↑</a></footer>
<script>
-const stage=document.getElementById('stage'),glass=document.getElementById('glass'),mapEl=document.getElementById('lg-map');
+const stage=document.getElementById('stage'),box=document.getElementById('lg-box'),glass=document.getElementById('glass'),mapEl=document.getElementById('lg-map');
const filt=document.getElementById('lg-filter'),fImg=document.getElementById('lg-img'),fDisp=document.getElementById('lg-disp');
const slowTog=document.getElementById('slow-tog'),vars=stage.style,reduce=matchMedia('(prefers-reduced-motion:reduce)');
// Chromium draws an SVG filter in backdrop-filter; Safari and Firefox do not, and CSS.supports() only checks the syntax, so the
@@ -195,38 +236,79 @@ const FRAME=1000/60,RUN_MS=3600,EMAX=.12,MAG=.15;
const SHAPES={card:[1,.62,.34],pill:[1.12,.42,.5],circle:[.68,.68,.5]};
let W=0,H=0,gw=0,gh=0,shape='card',bend=.42,x=0,y=0,run=null,drag=null,target=null,hold=0,holdFrom=null,raf=0,lastT=null,acc=0;
let lx=0,ly=0,vx=0,vy=0,a=0,b=0,va=0,vb=0; // where the last frame drew the glass, its smoothed speed (px/ms), its stretch (a, b) and its speed
+// See inside's drawing on the glass: the map's left half, the dashed line where the rim begins and the arrows (each over a dark edge)
+const mapHalf=glass.querySelector('.lg-mh'),[rimU,rimEl,arrU,arrEl]=glass.querySelector('.lg-x').children;
+// Compare's first half: a copy of the box with the scene and a plain glass (no map, no bend), made once, inert and hidden from
+// screen readers. It takes no input: place() gives its glass the real glass's place and stretch, so the two move in step.
+const twin=document.createElement('div'),plain=document.createElement('div'),plainName=box.querySelector('.lg-half').cloneNode(true);
+twin.className='lg-box lg-twin';twin.inert=true;twin.setAttribute('aria-hidden','true');plain.className='lg-glass lg-plain';plainName.textContent='Plain glass';
+twin.append(box.querySelector('.lg-scene').cloneNode(true),plainName,plain);box.before(twin);
+// What the glass says it shows in each mode; where the bend cannot be drawn, the notes say what shows instead
+let mode='normal';
+const NAMES={normal:glass.getAttribute('aria-label'),
+ inside:'Glass over a colorful picture, its left half showing the bend map, with arrows pointing to what each spot shows. Drag it, or press the arrow keys to move it.',
+ compare:'Liquid glass over a colorful picture, beside the same glass without the bend. Drag it, or press the arrow keys to move it.'};
+if(!REFRACT){
+ document.querySelector('[data-hb-for="inside"]').textContent='Inside, a bend map would steer the glass (left half: red sideways, green up and down); this browser shows frosted glass, so only the arrows point to what each spot would show.';
+ document.querySelector('[data-hb-for="compare"]').textContent='This browser cannot draw the bend, so Plain glass and Liquid glass look the same here; open the page in Chrome or Edge on a computer or Android to see the edge bend.';
+}
+// How a spot of the glass, (X, Y) from its middle, reads the picture: its shift as a share of the deepest one, or null outside the
+// rounded corners. Near the rim every spot reads the picture from further in, most at the very edge (the rim magnifies), and a
+// little everywhere toward the middle (the whole glass magnifies slightly).
+function bendAt(X,Y){
+ const hw=gw/2,hh=gh/2,r=gh*SHAPES[shape][2],B=Math.min(hw,hh)*.7,qx=Math.abs(X)-hw+r,qy=Math.abs(Y)-hh+r;
+ let e,nx=0,ny=0; // e: the distance in from the edge; (nx, ny): the way out
+ if(qx>0&&qy>0){const l=Math.hypot(qx,qy);e=r-l;nx=Math.sign(X)*qx/l;ny=Math.sign(Y)*qy/l;}
+ else if(qx>qy){e=r-qx;nx=Math.sign(X);}else{e=r-qy;ny=Math.sign(Y);}
+ if(e<0)return null;
+ const m=(1-Math.min(1,e/B))**2;return [nx*m+MAG*X/hw,ny*m+MAG*Y/hh];
+}
// The bend map, one pixel per CSS pixel of the glass. Red is the sideways shift and green the shift up or down (128: none).
-// Near the rim every pixel reads the picture from further in, most at the very edge (the rim magnifies), and a little
-// everywhere toward the middle (the whole glass magnifies slightly). Outside the rounded corners it stays at 128.
function drawMap(){
const c=document.createElement('canvas');c.width=gw;c.height=gh;
- const g=c.getContext('2d'),img=g.createImageData(gw,gh),d=img.data,hw=gw/2,hh=gh/2,r=gh*SHAPES[shape][2],B=Math.min(hw,hh)*.7;
+ const g=c.getContext('2d'),img=g.createImageData(gw,gh),d=img.data,hw=gw/2,hh=gh/2;
for(let j=0;j<gh;j++)for(let i=0;i<gw;i++){
- const X=i+.5-hw,Y=j+.5-hh,qx=Math.abs(X)-hw+r,qy=Math.abs(Y)-hh+r,k=(j*gw+i)*4;
- let e,nx=0,ny=0; // e: the distance in from the edge; (nx, ny): the way out
- if(qx>0&&qy>0){const l=Math.hypot(qx,qy);e=r-l;nx=Math.sign(X)*qx/l;ny=Math.sign(Y)*qy/l;}
- else if(qx>qy){e=r-qx;nx=Math.sign(X);}else{e=r-qy;ny=Math.sign(Y);}
- const m=e<0?0:(1-Math.min(1,e/B))**2,z=e<0?0:MAG;
- d[k]=128-127*(nx*m+z*X/hw)/(1+MAG);d[k+1]=128-127*(ny*m+z*Y/hh)/(1+MAG);d[k+2]=128;d[k+3]=255;
+ const v=bendAt(i+.5-hw,j+.5-hh),k=(j*gw+i)*4;
+ d[k]=v?128-127*v[0]/(1+MAG):128;d[k+1]=v?128-127*v[1]/(1+MAG):128;d[k+2]=128;d[k+3]=255;
}
- g.putImageData(img,0,0);const url=c.toDataURL();fImg.setAttribute('href',url);mapEl.style.backgroundImage='url('+url+')';
- for(const el of [filt,fImg]){el.setAttribute('width',gw);el.setAttribute('height',gh);}setBend();
+ g.putImageData(img,0,0);const url=c.toDataURL();fImg.setAttribute('href',url);mapEl.style.backgroundImage=mapHalf.style.backgroundImage='url('+url+')';
+ for(const el of [filt,fImg]){el.setAttribute('width',gw);el.setAttribute('height',gh);}drawSpots();setBend();
}
// The filter shifts a pixel by up to half its scale; at the very edge that is the bend times the rim's width
-function setBend(){fDisp.setAttribute('scale',(2*bend*Math.min(gw,gh)*.35*(1+MAG)).toFixed(1));vars.setProperty('--lg-rim',Math.round(bend*70-6)+'px');}
+function setBend(){fDisp.setAttribute('scale',(2*bend*Math.min(gw,gh)*.35*(1+MAG)).toFixed(1));vars.setProperty('--lg-rim',Math.round(bend*70-6)+'px');drawArrows();}
+// See inside: spots about every 16px (further apart on a big glass, so the long arrows at the rim stay clear of the next spot),
+// each with bendAt()'s shift, and the dashed line where the rim begins (the rim's width in from the edge)
+let spots=[];
+function drawSpots(){
+ const S=Math.max(16,Math.round(Math.min(gw,gh)/7)),n=Math.floor((gw-6)/S)+1,m=Math.floor((gh-6)/S)+1;spots=[];
+ for(let j=0;j<m;j++)for(let i=0;i<n;i++){const X=(i-(n-1)/2)*S,Y=(j-(m-1)/2)*S,v=bendAt(X,Y);if(v)spots.push([X+gw/2,Y+gh/2,v[0],v[1]]);}
+ const B=Math.min(gw,gh)*.35,R={x:B,y:B,width:gw-2*B,height:gh-2*B,rx:Math.max(0,gh*SHAPES[shape][2]-B)};
+ for(const el of [rimU,rimEl])for(const k in R)el.setAttribute(k,R[k].toFixed(1));
+}
+// Each spot's arrow points to where it reads the picture from, as long as the filter shifts it now (half its scale for a share
+// of 1 + MAG); a spot that barely moves is a dot
+function drawArrows(){
+ const s=fDisp.getAttribute('scale')/2/(1+MAG),f=n=>n.toFixed(1);let d='';
+ for(const [px,py,ux,uy] of spots){
+ const qx=px-s*ux,qy=py-s*uy,l=s*Math.hypot(ux,uy),t=Math.atan2(qy-py,qx-px),h=Math.min(5,l*.45);
+ d+=l<3?`M${f(px)} ${f(py)}h0`:`M${f(px)} ${f(py)}L${f(qx)} ${f(qy)}M${f(qx-h*Math.cos(t-.55))} ${f(qy-h*Math.sin(t-.55))}L${f(qx)} ${f(qy)}L${f(qx-h*Math.cos(t+.55))} ${f(qy-h*Math.sin(t+.55))}`;
+ }
+ arrEl.setAttribute('d',d);arrU.setAttribute('d',d);
+}
const 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 stripes
-function 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), at most 55% of its height. A new size draws the map
+function place(){glass.style.transform=plain.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 its box'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.
+// The box is the stage, or in Compare its half.
function layout(){
- const w=stage.clientWidth,h=stage.clientHeight;if(!w||!h)return;
+ const w=box.clientWidth,h=box.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,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(nw!==gw||nh!==gh){gw=nw;gh=nh;for(const g of [glass,plain]){g.style.width=gw+'px';g.style.height=gh+'px';g.style.borderRadius=Math.round(gh*sr)+'px';}drawMap();}
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();
}
@@ -268,7 +350,8 @@ glass.addEventListener('pointermove',e=>{if(drag&&e.pointerId===drag.id){x=cx(e.
const letGo=e=>{if(drag&&e.pointerId===drag.id){drag=null;glass.classList.remove('lg-grab');wake();}};
['pointerup','pointercancel','lostpointercapture'].forEach(t=>glass.addEventListener(t,letGo));
function goTo(p){run=null;if(reduce.matches){[x,y]=p;target=null;place();}else{target=p;wake();}}
-stage.addEventListener('click',e=>{if(!glass.contains(e.target)){const r=stage.getBoundingClientRect();goTo([cx(e.clientX-r.left),cy(e.clientY-r.top)]);}});
+// In Compare only a tap on the real half counts (the copy is inert, so a tap there reaches the stage), measured from that half
+stage.addEventListener('click',e=>{if(!glass.contains(e.target)&&(mode!=='compare'||box.contains(e.target))){const r=stage.getBoundingClientRect();goTo([cx(e.clientX-r.left-box.offsetLeft),cy(e.clientY-r.top-box.offsetTop)]);}});
// The arrow keys move it a step (three with Shift), and quick presses add up
glass.addEventListener('keydown',e=>{
const k={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[e.key];if(!k)return;
@@ -303,6 +386,10 @@ choices('frost-seg',d=>{vars.setProperty('--lg-blur',d.f+'px');vars.setProperty(
choices('tint-sw',d=>{vars.setProperty('--lg-tint',d.c);vars.setProperty('--lg-tp',d.p+'%');});
choices('shape-seg',d=>{shape=d.s;gw=0;layout();});
document.getElementById('map-tog').addEventListener('change',e=>{mapEl.hidden=!e.target.checked;});
+// The mode switch, drawn at once: See inside draws on the glass by its styles; Compare halves the box, and layout() fits the
+// glass to its half, keeping its place, a glide and a run at their shares (Normal brings the whole box back). The shared script
+// then presses Show me (not under reduced motion), which plays it.
+document.addEventListener('hb:mode',e=>{mode=e.detail.mode;glass.setAttribute('aria-label',NAMES[mode]);layout();});
addEventListener('resize',layout);
layout();
</script>