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.

fix: audit and repair demos in sections 2-6 (84 pages)

matin3c7664cabf63
diff --git a/animations/02-entrance-and-exit/blur-in/index.html b/animations/02-entrance-and-exit/blur-in/index.html
index c0011053..aa0f0b3c 100644
--- a/animations/02-entrance-and-exit/blur-in/index.html
+++ b/animations/02-entrance-and-exit/blur-in/index.html
@@ -40,7 +40,7 @@
.card-title{font-size:clamp(16px,2.5vw,22px);font-weight:bold;margin-bottom:8px}
.card-sub{font-size:11px;color:var(--ui-muted);line-height:1.65}
/* mode classes */
- .card[data-mode="blur-only"]{opacity:1!important;transition:filter var(--dur) var(--ease)!important}
+ .card[data-mode="blur-only"]{opacity:1!important;transform:none!important;transition:filter var(--dur) var(--ease)!important}
.card[data-mode="blur-only"].in{opacity:1;filter:blur(0)}
.card[data-mode="fade-only"]{filter:none!important;transform:none!important;transition:opacity var(--dur) var(--ease)!important}
.card[data-mode="fade-only"].in{opacity:1}
@@ -56,7 +56,7 @@
.sv{width:38px;text-align:right;color:var(--ui-text)}
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.seg{display:flex;gap:3px;flex-wrap:wrap}
- .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:36px}
+ .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:44px}
.seg button.on{border-color:var(--ui-accent);color:var(--ui-accent);background:rgba(95,216,138,.12)}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
@@ -64,7 +64,7 @@
button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
@media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -145,7 +145,7 @@ body{padding-top:46px}
stEl.textContent=cls==='in'?'playing in':'playing out';
animTimer=setTimeout(()=>stEl.textContent=cls==='in'?'visible':'hidden',dur);
}
- function stopLoop(){looping=false;clearTimeout(loopTimer);clearTimeout(animTimer);loopTog.checked=false}
+ function stopLoop(){looping=false;clearTimeout(loopTimer);loopTog.checked=false}
function loop(){_trigger('in');loopTimer=setTimeout(()=>{_trigger('out');loopTimer=setTimeout(()=>{if(looping)loop()},dur+400)},dur+900)}
document.getElementById('btn-in').addEventListener('click',()=>{stopLoop();_trigger('in')});
@@ -154,7 +154,7 @@ body{padding-top:46px}
loopTog.addEventListener('change',()=>{looping=loopTog.checked;if(looping&&motionOk)loop();else stopLoop()});
document.querySelectorAll('#mode-seg button').forEach(b=>b.addEventListener('click',()=>{
document.querySelectorAll('#mode-seg button').forEach(x=>x.classList.remove('on'));b.classList.add('on');
- card.dataset.mode=b.dataset.m;card.classList.remove('in');stEl.textContent='hidden';
+ clearTimeout(animTimer);card.dataset.mode=b.dataset.m;card.classList.remove('in');stEl.textContent='hidden';
}));
blurSl.addEventListener('input',()=>{
const v=blurSl.value+'px';blurV.textContent=blurSl.value+'px';
diff --git a/animations/02-entrance-and-exit/bounce-in/index.html b/animations/02-entrance-and-exit/bounce-in/index.html
index 9da00773..d1995b9c 100644
--- a/animations/02-entrance-and-exit/bounce-in/index.html
+++ b/animations/02-entrance-and-exit/bounce-in/index.html
@@ -52,7 +52,7 @@
.sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
.sv{width:38px;text-align:right;color:var(--ui-text)}
.seg{display:flex;gap:3px}
- .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:36px}
+ .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:44px}
.seg button.on{border-color:var(--ui-accent);color:var(--ui-accent);background:rgba(95,216,138,.12)}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
@@ -60,7 +60,7 @@
button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
@media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}}
</style>
<style id="kf-style"></style>
<style id="ah-inject">
@@ -179,7 +179,7 @@ body{padding-top:46px}
const d=cls==='out'?Math.round(dur*0.5):dur;
animTimer=setTimeout(()=>stEl.textContent=cls==='in'?'visible':'hidden',d);
}
- function stopLoop(){looping=false;clearTimeout(loopTimer);clearTimeout(animTimer);loopTog.checked=false}
+ function stopLoop(){looping=false;clearTimeout(loopTimer);loopTog.checked=false}
function loop(){_trigger('in');loopTimer=setTimeout(()=>{_trigger('out');loopTimer=setTimeout(()=>{if(looping)loop()},Math.round(dur*0.5)+400)},dur+800)}
document.getElementById('btn-in').addEventListener('click',()=>{stopLoop();_trigger('in')});
diff --git a/animations/02-entrance-and-exit/clip-path-reveal/index.html b/animations/02-entrance-and-exit/clip-path-reveal/index.html
index 452a9456..0b27ca09 100644
--- a/animations/02-entrance-and-exit/clip-path-reveal/index.html
+++ b/animations/02-entrance-and-exit/clip-path-reveal/index.html
@@ -41,7 +41,7 @@
.surface-title{font-size:clamp(22px,4vw,36px);font-weight:bold;color:#fff}
.clip-outline{position:absolute;inset:0;pointer-events:none;border:2px dashed var(--ui-accent);opacity:0;transition:opacity .3s;border-radius:12px}
.clip-outline.show{opacity:.6}
- @media(prefers-reduced-motion:reduce){.surface{transition:opacity 400ms linear!important;clip-path:none!important}.surface.in{opacity:1}}
+ @media(prefers-reduced-motion:reduce){.surface{opacity:0;transition:opacity 400ms linear!important;clip-path:none!important}.surface.in{opacity:1}}
aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
.note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
.lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
@@ -61,7 +61,7 @@
button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
@media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}aside{width:100%}:root{--stage-h:480px}.stage{flex:none}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}aside{width:100%}:root{--stage-h:480px}.stage{flex:none}.seg button{min-height:44px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -168,6 +168,11 @@ body{padding-top:46px}
cpVal.textContent=c.out;
}
+ // Re-arm the hidden state without tweening old clip -> new clip (inset top -> inset left would flash a partial reveal)
+ function resetHidden(){
+ clearTimeout(animTimer);surface.style.transition='none';applyClips();surface.classList.remove('in');
+ void surface.offsetWidth;surface.style.transition='';stEl.textContent='hidden';
+ }
function _trigger(cls){
clearTimeout(animTimer);surface.classList.remove('in');void surface.offsetWidth;
if(cls==='in'){surface.classList.add('in');cpVal.textContent=getClips().in;}
@@ -188,11 +193,11 @@ body{padding-top:46px}
const dirHead=document.getElementById('dir-head');
document.getElementById('dir-seg').style.display=shape==='inset'?'flex':'none';
dirHead.style.display=shape==='inset'?'block':'none';
- applyClips();surface.classList.remove('in');stEl.textContent='hidden';
+ resetHidden();
}));
document.querySelectorAll('#dir-seg button').forEach(b=>b.addEventListener('click',()=>{
document.querySelectorAll('#dir-seg button').forEach(x=>x.classList.remove('on'));b.classList.add('on');
- dir=b.dataset.d;applyClips();surface.classList.remove('in');stEl.textContent='hidden';
+ dir=b.dataset.d;resetHidden();
}));
durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms';document.documentElement.style.setProperty('--dur',dur+'ms')});
easeSel.addEventListener('change',()=>document.documentElement.style.setProperty('--ease',easeSel.value));
diff --git a/animations/02-entrance-and-exit/curtain-reveal/index.html b/animations/02-entrance-and-exit/curtain-reveal/index.html
index 2e1e16de..1f4cee27 100644
--- a/animations/02-entrance-and-exit/curtain-reveal/index.html
+++ b/animations/02-entrance-and-exit/curtain-reveal/index.html
@@ -37,24 +37,20 @@
.content-title{font-size:clamp(24px,4vw,42px);font-weight:bold;line-height:1.1}
.content-sub{font-size:12px;color:var(--ui-muted);max-width:260px;line-height:1.6}
/* Curtains */
- .curtain,.curtain-b{position:absolute;background:var(--curtain-color);z-index:2;transition:transform var(--dur) var(--ease)}
+ /* --from / --to are the off-stage positions; JS sets them per direction */
+ .curtain,.curtain-b{position:absolute;background:var(--curtain-color);z-index:2;transition:transform var(--dur) var(--ease);transform:var(--from)}
/* Horizontal */
- .curtain[data-axis=h]{inset:0 auto 0 0;width:100%;transform:translateX(-101%)}
- .curtain[data-axis=h].c-in{transform:translateX(0)}
- .curtain[data-axis=h].c-out{transform:translateX(101%)}
+ .curtain[data-axis=h]{inset:0 auto 0 0;width:100%;--from:translateX(-101%);--to:translateX(101%)}
/* Vertical */
- .curtain[data-axis=v]{inset:0 0 auto 0;height:100%;transform:translateY(-101%)}
- .curtain[data-axis=v].c-in{transform:translateY(0)}
- .curtain[data-axis=v].c-out{transform:translateY(101%)}
+ .curtain[data-axis=v]{inset:0 0 auto 0;height:100%;--from:translateY(-101%);--to:translateY(101%)}
/* Two-curtain halves */
- .curtain-b{z-index:2;transition:transform var(--dur) var(--ease)}
- .curtain-b[data-axis=h]{inset:0 0 0 auto;width:50%;transform:translateX(101%)}
+ .curtain-b[data-axis=h]{inset:0 0 0 auto;width:50%;--from:translateX(101%);--to:translateX(101%)}
.curtain[data-axis=h].twin{width:50%}
- .curtain-b[data-axis=h].c-in{transform:translateX(0)}
- .curtain-b[data-axis=h].c-out{transform:translateX(101%)}
+ .curtain.c-in,.curtain-b.c-in{transform:translate(0,0)}
+ .curtain.c-out,.curtain-b.c-out{transform:var(--to)}
/* Timeline */
.tl{display:flex;gap:4px;align-items:center;position:absolute;bottom:16px;left:50%;transform:translateX(-50%);pointer-events:none}
- .tl-seg{height:4px;border-radius:2px;width:48px;background:var(--ui-border);transition:background .2s}
+ .tl-seg{position:relative;height:4px;border-radius:2px;width:48px;background:var(--ui-border);transition:background .2s}
.tl-seg.active{background:var(--ui-accent)}
.tl-label{font-size:8px;color:var(--ui-muted);position:absolute;bottom:-14px;white-space:nowrap}
@media(prefers-reduced-motion:reduce){.curtain,.curtain-b{transition:none!important}}
@@ -68,10 +64,10 @@
.sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
.sv{width:38px;text-align:right;color:var(--ui-text)}
.seg{display:flex;gap:3px;flex-wrap:wrap}
- .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:36px}
+ .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:44px}
.seg button.on{border-color:var(--ui-accent);color:var(--ui-accent);background:rgba(95,216,138,.12)}
.swatches{display:flex;gap:5px}
- .swatch{width:26px;height:26px;border-radius:4px;cursor:pointer;border:2px solid transparent;min-height:auto}
+ .swatch{flex:1;min-width:0;min-height:44px;padding:9px 3px;background:var(--c);background-clip:content-box;border-radius:4px;cursor:pointer;border:2px solid transparent}
.swatch.on{border-color:var(--ui-text)}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
@@ -79,7 +75,7 @@
button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
@media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -123,11 +119,11 @@ body{padding-top:46px}
<div class="div"></div>
<div class="lbl">Curtain color</div>
<div class="swatches" id="swatches">
- <div class="swatch on" data-c="#111827" style="background:#111827" tabindex="0" role="button" aria-label="Dark"></div>
- <div class="swatch" data-c="#1e3a5f" style="background:#1e3a5f" tabindex="0" role="button" aria-label="Ink blue"></div>
- <div class="swatch" data-c="#5c1a1a" style="background:#5c1a1a" tabindex="0" role="button" aria-label="Warm red"></div>
- <div class="swatch" data-c="#f0ede8" style="background:#f0ede8" tabindex="0" role="button" aria-label="Off-white"></div>
- <div class="swatch" data-c="#8a6e14" style="background:#8a6e14" tabindex="0" role="button" aria-label="Gold"></div>
+ <div class="swatch on" data-c="#111827" style="--c:#111827" tabindex="0" role="button" aria-label="Dark"></div>
+ <div class="swatch" data-c="#1e3a5f" style="--c:#1e3a5f" tabindex="0" role="button" aria-label="Ink blue"></div>
+ <div class="swatch" data-c="#5c1a1a" style="--c:#5c1a1a" tabindex="0" role="button" aria-label="Warm red"></div>
+ <div class="swatch" data-c="#f0ede8" style="--c:#f0ede8" tabindex="0" role="button" aria-label="Off-white"></div>
+ <div class="swatch" data-c="#8a6e14" style="--c:#8a6e14" tabindex="0" role="button" aria-label="Gold"></div>
</div>
<div class="lbl">Direction</div>
<div class="seg" id="dir-seg">
@@ -161,8 +157,14 @@ body{padding-top:46px}
let dur=500,pause=300,axis='h',dirMode='ltr',twin=false,looping=false,loopTimer=null,busy=false;
function setTL(i){document.querySelectorAll('.tl-seg').forEach((s,j)=>s.classList.toggle('active',j===i))}
- function clearCurtains(){
- [curtain,curtainB].forEach(c=>{c.className=c.id==='curtain'?'curtain':'curtain-b';c.dataset.axis=axis});
+ // Snap both curtains back off-stage without animating (otherwise the bar would
+ // slide from its exit side back to its entry side, or enter from the wrong edge).
+ function clearCurtains(setup){
+ [curtain,curtainB].forEach(c=>{c.style.transition='none';c.className=c.id==='curtain'?'curtain':'curtain-b';c.dataset.axis=axis;c.style.removeProperty('--from');c.style.removeProperty('--to')});
+ curtainB.style.display=(twin&&axis==='h')?'block':'none';
+ if(setup)setup();
+ void curtain.offsetWidth;
+ [curtain,curtainB].forEach(c=>c.style.removeProperty('transition'));
}
function getInDir(){
@@ -176,15 +178,14 @@ body{padding-top:46px}
function play(){
if(busy)return;busy=true;
- clearCurtains();
- if(twin&&axis==='h'){
- curtain.classList.add('twin');curtainB.style.display='block';
- curtain.style.transform='translateX(-101%)';curtainB.style.transform='translateX(101%)';
- } else {
- curtain.style.transform=getInDir();curtainB.style.display='none';
- }
+ clearCurtains(()=>{
+ if(twin&&axis==='h'){
+ curtain.classList.add('twin'); // halves use the CSS defaults: left from -101%, right from 101%
+ } else {
+ curtain.style.setProperty('--from',getInDir());curtain.style.setProperty('--to',getOutDir());
+ }
+ });
stEl.textContent='entering';setTL(0);
- void curtain.offsetWidth;
// Stage A: curtain enters
if(twin&&axis==='h'){curtain.classList.add('c-in');curtainB.classList.add('c-in');}
else curtain.classList.add('c-in');
@@ -208,18 +209,27 @@ body{padding-top:46px}
document.getElementById('btn-rst').addEventListener('click',()=>{
stopLoop();clearCurtains();stEl.textContent='idle';setTL(-1);
});
- loopTog.addEventListener('change',()=>{looping=loopTog.checked;if(looping&&motionOk)play();else stopLoop()});
+ loopTog.addEventListener('change',()=>{
+ looping=loopTog.checked;
+ if(looping&&motionOk){if(!busy)play()}
+ else if(looping)stopLoop(); // reduced motion: never auto-play
+ else if(!busy)clearTimeout(loopTimer); // let a running cycle finish, just don't queue another
+ });
document.querySelectorAll('#dir-seg button').forEach(b=>b.addEventListener('click',()=>{
document.querySelectorAll('#dir-seg button').forEach(x=>x.classList.remove('on'));b.classList.add('on');
- axis=b.dataset.ax;dirMode=b.dataset.dir;clearCurtains();
- }));
- document.querySelectorAll('.swatch').forEach(s=>s.addEventListener('click',()=>{
- document.querySelectorAll('.swatch').forEach(x=>x.classList.remove('on'));s.classList.add('on');
- document.documentElement.style.setProperty('--curtain-color',s.dataset.c);
+ axis=b.dataset.ax;dirMode=b.dataset.dir;if(!busy)clearCurtains();
}));
+ document.querySelectorAll('.swatch').forEach(s=>{
+ const pick=()=>{
+ document.querySelectorAll('.swatch').forEach(x=>x.classList.remove('on'));s.classList.add('on');
+ document.documentElement.style.setProperty('--curtain-color',s.dataset.c);
+ };
+ s.addEventListener('click',pick);
+ s.addEventListener('keydown',e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();pick()}});
+ });
durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms';document.documentElement.style.setProperty('--dur',dur+'ms')});
pauseSl.addEventListener('input',()=>{pause=+pauseSl.value;pauseV.textContent=pause+'ms'});
- twinTog.addEventListener('change',()=>{twin=twinTog.checked;clearCurtains()});
+ twinTog.addEventListener('change',()=>{twin=twinTog.checked;if(!busy)clearCurtains()});
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
</body>
diff --git a/animations/02-entrance-and-exit/fade-in-out/index.html b/animations/02-entrance-and-exit/fade-in-out/index.html
index 6615fb95..14dc84f6 100644
--- a/animations/02-entrance-and-exit/fade-in-out/index.html
+++ b/animations/02-entrance-and-exit/fade-in-out/index.html
@@ -54,7 +54,7 @@
button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
@media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}.stage{flex:0 0 auto}aside{width:100%}:root{--stage-h:480px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -127,17 +127,24 @@ body{padding-top:46px}
function setOp(v){opEl.textContent=v}
function setSt(s,o){stEl.textContent=s;setOp(o)}
- function _trigger(cls){
- clearTimeout(animTimer);
+ function snapHidden(){ // remove .in with the transition suppressed ('important' beats the reduced-motion rule)
+ card.style.setProperty('transition','none','important');
card.classList.remove('in');
void card.offsetWidth;
- if(cls==='in'){card.classList.add('in');setSt('playing in','↑');}
- else setSt('playing out','↓');
- animTimer=setTimeout(()=>setSt(cls==='in'?'visible':'hidden',cls==='in'?'1.00':'0.00'),dur);
+ card.style.removeProperty('transition');
+ }
+ function _trigger(cls){
+ clearTimeout(animTimer);
+ if(cls==='in'){
+ snapHidden(); // snap to 0 so a replay restarts from invisible
+ card.classList.add('in');setSt('playing in','↑');
+ }
+ else{card.classList.remove('in');setSt('playing out','↓');}
+ animTimer=setTimeout(()=>setSt(cls==='in'?'visible':'hidden',cls==='in'?'1.00':'0.00'),motionOk?dur:300);
}
function stopLoop(){
- looping=false;clearTimeout(loopTimer);clearTimeout(animTimer);
+ looping=false;clearTimeout(loopTimer);
if(loopTog)loopTog.checked=false;
}
function playIn(){stopLoop();_trigger('in')}
@@ -149,7 +156,7 @@ body{padding-top:46px}
document.getElementById('btn-in').addEventListener('click',playIn);
document.getElementById('btn-out').addEventListener('click',playOut);
- document.getElementById('btn-rst').addEventListener('click',()=>{stopLoop();clearTimeout(animTimer);card.classList.remove('in');setSt('hidden','0.00')});
+ document.getElementById('btn-rst').addEventListener('click',()=>{stopLoop();clearTimeout(animTimer);snapHidden();setSt('hidden','0.00')});
loopTog.addEventListener('change',()=>{looping=loopTog.checked;if(looping&&motionOk)loop();else stopLoop()});
durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms';document.documentElement.style.setProperty('--dur',dur+'ms')});
easeSel.addEventListener('change',()=>document.documentElement.style.setProperty('--ease',easeSel.value));
diff --git a/animations/02-entrance-and-exit/flip-in/index.html b/animations/02-entrance-and-exit/flip-in/index.html
index d0d5cf4a..2ed86aea 100644
--- a/animations/02-entrance-and-exit/flip-in/index.html
+++ b/animations/02-entrance-and-exit/flip-in/index.html
@@ -50,7 +50,7 @@
.sv{width:42px;text-align:right;color:var(--ui-text)}
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.seg{display:flex;gap:3px;flex-wrap:wrap}
- .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:36px}
+ .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:44px}
.seg button.on{border-color:var(--ui-accent);color:var(--ui-accent);background:rgba(95,216,138,.12)}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
@@ -58,7 +58,7 @@
button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
@media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none}aside{width:100%}:root{--stage-h:480px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -152,6 +152,7 @@ body{padding-top:46px}
document.documentElement.style.setProperty('--rot-x',rx);
rotVal.textContent=axis==='both'?`X/Y: ${rot}°`:axis+`: ${rot}°`;
card.classList.remove('in');void card.offsetWidth;
+ if(!looping){clearTimeout(animTimer);stEl.textContent='hidden'}
if(!fadeTog.checked)card.style.opacity='1';else card.style.opacity='';
}
@@ -161,7 +162,7 @@ body{padding-top:46px}
stEl.textContent=cls==='in'?'playing in':'playing out';
animTimer=setTimeout(()=>stEl.textContent=cls==='in'?'visible':'hidden',dur);
}
- function stopLoop(){looping=false;clearTimeout(loopTimer);clearTimeout(animTimer);loopTog.checked=false}
+ function stopLoop(){looping=false;clearTimeout(loopTimer);loopTog.checked=false}
function loop(){_trigger('in');loopTimer=setTimeout(()=>{_trigger('out');loopTimer=setTimeout(()=>{if(looping)loop()},dur+400)},dur+800)}
document.getElementById('btn-in').addEventListener('click',()=>{stopLoop();_trigger('in')});
diff --git a/animations/02-entrance-and-exit/letter-by-letter-stagger/index.html b/animations/02-entrance-and-exit/letter-by-letter-stagger/index.html
index 3a140a7a..5e0df1c8 100644
--- a/animations/02-entrance-and-exit/letter-by-letter-stagger/index.html
+++ b/animations/02-entrance-and-exit/letter-by-letter-stagger/index.html
@@ -65,7 +65,7 @@
button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
@media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}.stage{flex:none}aside{width:100%}.seg button{min-height:44px}:root{--stage-h:480px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -201,8 +201,8 @@ body{padding-top:46px}
document.querySelectorAll('#anim-seg button').forEach(x=>x.classList.remove('on'));b.classList.add('on');
anim=b.dataset.a;target.dataset.anim=anim;reset();
}));
- durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms';document.documentElement.style.setProperty('--dur',dur+'ms');buildSpans()});
- stagSl.addEventListener('input',()=>{stagger=+stagSl.value;stagV.textContent=stagger+'ms';document.documentElement.style.setProperty('--stagger',stagger+'ms');buildSpans()});
+ durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms';document.documentElement.style.setProperty('--dur',dur+'ms');reset()});
+ stagSl.addEventListener('input',()=>{stagger=+stagSl.value;stagV.textContent=stagger+'ms';document.documentElement.style.setProperty('--stagger',stagger+'ms');reset()});
txtIn.addEventListener('input',reset);cursorTog.addEventListener('change',reset);
buildSpans();
</script>
diff --git a/animations/02-entrance-and-exit/rotate-in/index.html b/animations/02-entrance-and-exit/rotate-in/index.html
index 73d6106f..bb06c3e9 100644
--- a/animations/02-entrance-and-exit/rotate-in/index.html
+++ b/animations/02-entrance-and-exit/rotate-in/index.html
@@ -53,7 +53,7 @@
.sv{width:42px;text-align:right;color:var(--ui-text)}
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.seg{display:flex;gap:3px;flex-wrap:wrap}
- .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:36px}
+ .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:44px}
.seg button.on{border-color:var(--ui-accent);color:var(--ui-accent);background:rgba(95,216,138,.12)}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
@@ -61,7 +61,7 @@
button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
@media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -159,9 +159,12 @@ body{padding-top:46px}
}
function _trigger(cls){
- clearTimeout(animTimer);icon.classList.remove('in','out');void icon.offsetWidth;
- applyRot();
- if(cls==='in')icon.classList.add('in');
+ clearTimeout(animTimer);applyRot();
+ if(cls==='in'){
+ // snap to the hidden pose without transitioning so a replay always spins in from the start
+ icon.style.setProperty('transition','none','important');icon.classList.remove('in');void icon.offsetWidth;
+ icon.style.removeProperty('transition');icon.classList.add('in');
+ }else icon.classList.remove('in');
stEl.textContent=cls==='in'?'playing in':'playing out';
animTimer=setTimeout(()=>stEl.textContent=cls==='in'?'visible':'hidden',dur);
}
diff --git a/animations/02-entrance-and-exit/scale-in/index.html b/animations/02-entrance-and-exit/scale-in/index.html
index faac2f25..e4340fff 100644
--- a/animations/02-entrance-and-exit/scale-in/index.html
+++ b/animations/02-entrance-and-exit/scale-in/index.html
@@ -50,7 +50,7 @@
.sv{width:38px;text-align:right;color:var(--ui-text)}
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.seg{display:flex;gap:3px;flex-wrap:wrap}
- .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:var(--mono);font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:36px}
+ .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:var(--mono);font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:44px}
.seg button.on{border-color:var(--ui-accent);color:var(--ui-accent);background:rgba(95,216,138,.12)}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
@@ -58,7 +58,7 @@
button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
@media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -142,7 +142,7 @@ body{padding-top:46px}
stEl.textContent=cls==='in'?'playing in':'playing out';
animTimer=setTimeout(()=>stEl.textContent=cls==='in'?'visible':'hidden',dur);
}
- function stopLoop(){looping=false;clearTimeout(loopTimer);clearTimeout(animTimer);loopTog.checked=false}
+ function stopLoop(){looping=false;clearTimeout(loopTimer);loopTog.checked=false}
function loop(){_trigger('in');loopTimer=setTimeout(()=>{_trigger('out');loopTimer=setTimeout(()=>{if(looping)loop()},dur+400)},dur+800)}
document.getElementById('btn-in').addEventListener('click',()=>{stopLoop();_trigger('in')});
@@ -152,7 +152,7 @@ body{padding-top:46px}
document.querySelectorAll('#orig-seg button').forEach(b=>b.addEventListener('click',()=>{
document.querySelectorAll('#orig-seg button').forEach(x=>x.classList.remove('on'));
b.classList.add('on');document.documentElement.style.setProperty('--origin',b.dataset.o);
- card.classList.remove('in');void card.offsetWidth;
+ clearTimeout(animTimer);card.classList.remove('in');stEl.textContent='hidden';void card.offsetWidth;
}));
ssSl.addEventListener('input',()=>{const v=ssSl.value/100;ssV.textContent=v.toFixed(2);scVal.textContent=v.toFixed(2);document.documentElement.style.setProperty('--ss',v)});
durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms';document.documentElement.style.setProperty('--dur',dur+'ms')});
diff --git a/animations/02-entrance-and-exit/slide-in/index.html b/animations/02-entrance-and-exit/slide-in/index.html
index 4732f7e9..87dab5e4 100644
--- a/animations/02-entrance-and-exit/slide-in/index.html
+++ b/animations/02-entrance-and-exit/slide-in/index.html
@@ -59,7 +59,7 @@
button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
@media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -153,12 +153,15 @@ body{padding-top:46px}
function _trigger(cls){
clearTimeout(animTimer);
+ // Snap back to the start offset without a transition so a repeated "Play in" replays from the edge.
+ if(cls==='in')card.style.setProperty('transition','none','important');
card.classList.remove('in');void card.offsetWidth;
+ card.style.removeProperty('transition');
if(cls==='in')card.classList.add('in');
stEl.textContent=cls==='in'?'playing in':'playing out';
animTimer=setTimeout(()=>stEl.textContent=cls==='in'?'visible':'hidden',dur);
}
- function stopLoop(){looping=false;clearTimeout(loopTimer);clearTimeout(animTimer);loopTog.checked=false}
+ function stopLoop(){looping=false;clearTimeout(loopTimer);loopTog.checked=false}
function playIn(){stopLoop();_trigger('in')}
function playOut(){stopLoop();_trigger('out')}
function loop(){_trigger('in');loopTimer=setTimeout(()=>{_trigger('out');loopTimer=setTimeout(()=>{if(looping)loop()},dur+400)},dur+800)}
diff --git a/animations/02-entrance-and-exit/slide-up-reveal/index.html b/animations/02-entrance-and-exit/slide-up-reveal/index.html
index df9a23f3..69b7cef0 100644
--- a/animations/02-entrance-and-exit/slide-up-reveal/index.html
+++ b/animations/02-entrance-and-exit/slide-up-reveal/index.html
@@ -40,7 +40,7 @@
[data-method="clippath"] .line.in{clip-path:inset(0% 0 0 0)}
.headline{font-family:monospace;font-size:clamp(28px,5vw,52px);font-weight:bold;text-align:center;line-height:1.1}
.sub-line{font-family:monospace;font-size:clamp(13px,2vw,16px);color:var(--ui-muted);text-align:center}
- @media(prefers-reduced-motion:reduce){.line{transition:opacity 300ms linear!important;transform:none!important;clip-path:none!important} .line.in{opacity:1!important}}
+ @media(prefers-reduced-motion:reduce){.line{opacity:0;transition:opacity 300ms linear!important;transform:none!important;clip-path:none!important} .line.in{opacity:1!important}}
aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
.note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
.lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
@@ -60,7 +60,7 @@
button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
@media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}.stage{flex:none}aside{width:100%}:root{--stage-h:480px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -132,7 +132,6 @@ body{padding-top:46px}
const stagSl=document.getElementById('stag-sl'),stagV=document.getElementById('stag-v');
const easeSel=document.getElementById('ease-sel');
const multiTog=document.getElementById('multi-tog'),loopTog=document.getElementById('loop-tog');
- const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
let dur=700,method='translatey',looping=false,loopTimer=null,animTimer=null;
const lines=()=>multiTog.checked?[...document.querySelectorAll('.line')]:[document.getElementById('l0')];
@@ -155,7 +154,7 @@ body{padding-top:46px}
document.getElementById('btn-in').addEventListener('click',playIn);
document.getElementById('btn-out').addEventListener('click',playOut);
document.getElementById('btn-rst').addEventListener('click',()=>{stopLoop();clearTimeout(animTimer);lines().forEach(l=>l.classList.remove('in'));stEl.textContent='hidden'});
- loopTog.addEventListener('change',()=>{looping=loopTog.checked;if(looping&&motionOk)loop();else stopLoop()});
+ loopTog.addEventListener('change',()=>{looping=loopTog.checked;if(looping)loop();else clearTimeout(loopTimer)});
document.querySelectorAll('#method-seg button').forEach(b=>b.addEventListener('click',()=>{
document.querySelectorAll('#method-seg button').forEach(x=>x.classList.remove('on'));
b.classList.add('on');method=b.dataset.m;stage.dataset.method=method;
@@ -168,7 +167,7 @@ body{padding-top:46px}
multiTog.addEventListener('change',()=>{
const ls=document.querySelectorAll('.line');
ls.forEach((l,i)=>{l.style.display=(!multiTog.checked&&i>0)?'none':'block';l.classList.remove('in')});
- stEl.textContent='hidden';
+ clearTimeout(animTimer);stEl.textContent='hidden';
});
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/02-entrance-and-exit/split-text-reveal/index.html b/animations/02-entrance-and-exit/split-text-reveal/index.html
index 5c81c4a7..51679c87 100644
--- a/animations/02-entrance-and-exit/split-text-reveal/index.html
+++ b/animations/02-entrance-and-exit/split-text-reveal/index.html
@@ -45,12 +45,12 @@
/* lines mode: each word gets line-height clipping */
[data-mode="lines"] .unit{display:block;overflow:hidden}
[data-mode="lines"] .unit-inner{display:block;transform:translateY(100%);transition:transform var(--dur) var(--ease) calc(var(--i)*var(--stagger))}
- [data-mode="lines"] .splitting.in .unit-inner{transform:none}
+ .splitting.in[data-mode="lines"] .unit-inner{transform:none}
[data-mode="lines"] .unit{opacity:1}
/* word spacing */
[data-mode="words"] .unit{margin-right:0.28em}
[data-mode="chars"] .unit{margin-right:0.01em}
- @media(prefers-reduced-motion:reduce){.unit,.unit-inner{transition:opacity 300ms linear!important;transform:none!important}.splitting.in .unit{opacity:1}}
+ @media(prefers-reduced-motion:reduce){.unit,.unit-inner{transition:opacity 300ms linear!important;transform:none!important}[data-mode="lines"] .unit{opacity:0}.splitting.in .unit{opacity:1}}
aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
.note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
.lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
@@ -71,7 +71,7 @@
button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
@media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}.seg button{min-height:44px}:root{--stage-h:480px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -166,16 +166,19 @@ body{padding-top:46px}
} else {
let units=[];
if(mode==='words'){units=text.split(/\s+/).filter(Boolean);}
- else{units=text.split('\n').filter(Boolean);if(units.length<2)units=text.match(/.{1,18}(\s|$)/g)||[text];}
+ else{units=(text.match(/.{1,18}(\s|$)|.{1,18}/g)||[text]).map(u=>u.trim()).filter(Boolean);}
units.forEach((u,i)=>{
const s=document.createElement('span');
s.className='unit';s.style.setProperty('--i',i);
- if(mode==='lines'){s.innerHTML=`<span class="unit-inner">${u.trim()}</span>`;}
+ if(mode==='lines'){const inner=document.createElement('span');inner.className='unit-inner';inner.textContent=u;s.appendChild(inner);}
else{s.textContent=u;}
target.appendChild(s);
if(mode==='words'&&i<units.length-1)target.appendChild(document.createTextNode(' '));
});
}
+ updateTotal();
+ }
+ function updateTotal(){
const n=target.querySelectorAll('.unit').length;
totalEl.textContent=Math.round(n*stagger+dur)+'ms';
}
@@ -188,27 +191,28 @@ body{padding-top:46px}
const n=target.querySelectorAll('.unit').length;
animTimer=setTimeout(()=>stEl.textContent=cls==='in'?'visible':'hidden',n*stagger+dur);
}
- function stopLoop(){looping=false;clearTimeout(loopTimer);clearTimeout(animTimer);loopTog.checked=false}
+ function stopLoop(){looping=false;clearTimeout(loopTimer);loopTog.checked=false}
+ function reset(){stopLoop();clearTimeout(animTimer);target.classList.remove('in');stEl.textContent='hidden'}
function playIn(){stopLoop();_trigger('in')}
function playOut(){stopLoop();_trigger('out')}
function loop(){_trigger('in');const n=target.querySelectorAll('.unit').length;const t=n*stagger+dur;loopTimer=setTimeout(()=>{_trigger('out');loopTimer=setTimeout(()=>{if(looping)loop()},t+400)},t+800)}
document.getElementById('btn-in').addEventListener('click',playIn);
document.getElementById('btn-out').addEventListener('click',playOut);
- document.getElementById('btn-rst').addEventListener('click',()=>{stopLoop();clearTimeout(animTimer);target.classList.remove('in');stEl.textContent='hidden'});
+ document.getElementById('btn-rst').addEventListener('click',reset);
loopTog.addEventListener('change',()=>{looping=loopTog.checked;if(looping&&motionOk)loop();else stopLoop()});
document.querySelectorAll('#mode-seg button').forEach(b=>b.addEventListener('click',()=>{
document.querySelectorAll('#mode-seg button').forEach(x=>x.classList.remove('on'));b.classList.add('on');
- mode=b.dataset.m;stopLoop();target.classList.remove('in');split();stEl.textContent='hidden';
+ mode=b.dataset.m;reset();split();
}));
document.querySelectorAll('#anim-seg button').forEach(b=>b.addEventListener('click',()=>{
document.querySelectorAll('#anim-seg button').forEach(x=>x.classList.remove('on'));b.classList.add('on');
- anim=b.dataset.a;target.dataset.anim=anim;stopLoop();target.classList.remove('in');stEl.textContent='hidden';
+ anim=b.dataset.a;target.dataset.anim=anim;reset();
}));
- durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms';document.documentElement.style.setProperty('--dur',dur+'ms');split()});
- stagSl.addEventListener('input',()=>{stagger=+stagSl.value;stagV.textContent=stagger+'ms';document.documentElement.style.setProperty('--stagger',stagger+'ms');split()});
+ durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms';document.documentElement.style.setProperty('--dur',dur+'ms');updateTotal()});
+ stagSl.addEventListener('input',()=>{stagger=+stagSl.value;stagV.textContent=stagger+'ms';document.documentElement.style.setProperty('--stagger',stagger+'ms');updateTotal()});
easeSel.addEventListener('change',()=>document.documentElement.style.setProperty('--ease',easeSel.value));
- txtIn.addEventListener('input',()=>{stopLoop();target.classList.remove('in');split();stEl.textContent='hidden'});
+ txtIn.addEventListener('input',()=>{reset();split()});
split();
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/02-entrance-and-exit/word-by-word-reveal/index.html b/animations/02-entrance-and-exit/word-by-word-reveal/index.html
index 72936a34..e67adcc1 100644
--- a/animations/02-entrance-and-exit/word-by-word-reveal/index.html
+++ b/animations/02-entrance-and-exit/word-by-word-reveal/index.html
@@ -33,7 +33,7 @@
.stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:var(--bg);display:flex;align-items:center;justify-content:center;overflow:hidden;padding:clamp(20px,5vw,56px)}
#text-target{font-family:monospace;font-size:clamp(18px,3vw,28px);font-weight:bold;text-align:center;line-height:1.55;max-width:520px}
.word{display:inline-block;margin-right:0.28em;
- opacity:0;transition:opacity var(--dur) var(--ease) calc(var(--i)*var(--stagger)),transform var(--dur) var(--ease) calc(var(--i)*var(--stagger))}
+ opacity:0;transition:opacity var(--dur) var(--ease) calc(var(--i)*var(--stagger)),transform var(--dur) var(--ease) calc(var(--i)*var(--stagger)),filter var(--dur) var(--ease) calc(var(--i)*var(--stagger))}
[data-anim="fade-up"] .word{transform:translateY(0.4em)}
[data-anim="blur"] .word{filter:blur(8px);transform:none}
[data-anim="scale"] .word{transform:scale(0.6)}
@@ -59,7 +59,7 @@
button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
@media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -165,16 +165,16 @@ Software made with care.</textarea>
if(cls==='in')target.classList.add('in');
stEl.textContent=cls==='in'?'playing in':'playing out';
const words=target.querySelectorAll('.word');
- const maxIdx=Math.max(...[...words].map(w=>parseFloat(w.style.getPropertyValue('--i'))||0));
+ const maxIdx=Math.max(0,...[...words].map(w=>parseFloat(w.style.getPropertyValue('--i'))||0));
animTimer=setTimeout(()=>stEl.textContent=cls==='in'?'visible':'hidden',maxIdx*stagger+dur+200);
}
- function stopLoop(){looping=false;clearTimeout(loopTimer);clearTimeout(animTimer);loopTog.checked=false}
+ function stopLoop(){looping=false;clearTimeout(loopTimer);loopTog.checked=false}
function playIn(){stopLoop();_trigger('in')}
function playOut(){stopLoop();_trigger('out')}
function loop(){
_trigger('in');
const words=target.querySelectorAll('.word');
- const maxIdx=Math.max(...[...words].map(w=>parseFloat(w.style.getPropertyValue('--i'))||0));
+ const maxIdx=Math.max(0,...[...words].map(w=>parseFloat(w.style.getPropertyValue('--i'))||0));
const t=maxIdx*stagger+dur;
loopTimer=setTimeout(()=>{_trigger('out');loopTimer=setTimeout(()=>{if(looping)loop()},t+400)},t+1000);
}
@@ -188,7 +188,7 @@ Software made with care.</textarea>
easeSel.addEventListener('change',()=>document.documentElement.style.setProperty('--ease',easeSel.value));
animSel.addEventListener('change',()=>{target.dataset.anim=animSel.value});
punctTog.addEventListener('change',buildWords);
- txtIn.addEventListener('input',()=>{stopLoop();target.classList.remove('in');buildWords();stEl.textContent='hidden'});
+ txtIn.addEventListener('input',()=>{stopLoop();clearTimeout(animTimer);target.classList.remove('in');buildWords();stEl.textContent='hidden'});
buildWords();
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/03-page-transitions/blur-transition/index.html b/animations/03-page-transitions/blur-transition/index.html
index 512074fd..49f96ef2 100644
--- a/animations/03-page-transitions/blur-transition/index.html
+++ b/animations/03-page-transitions/blur-transition/index.html
@@ -65,7 +65,7 @@
.log-row{font-size:9px;color:var(--ui-muted)}
button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}.nav-btn:hover{border-color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}.nav-btn,button.rst{min-height:44px}}
@media(prefers-reduced-motion:reduce){.page{transition:none!important;filter:none!important}}
</style>
<style id="ah-inject">
diff --git a/animations/03-page-transitions/crossfade/index.html b/animations/03-page-transitions/crossfade/index.html
index fbc30ca7..926182bb 100644
--- a/animations/03-page-transitions/crossfade/index.html
+++ b/animations/03-page-transitions/crossfade/index.html
@@ -66,7 +66,7 @@
.log-row{font-size:9px;color:var(--ui-muted)}
button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}.stage{flex:none;width:100%}aside{width:100%}.nav-btn,.seg button,button.rst{min-height:44px}:root{--stage-h:480px}}
@media(prefers-reduced-motion:reduce){.page{transition:none!important}}
</style>
<style id="ah-inject">
diff --git a/animations/03-page-transitions/dissolve/index.html b/animations/03-page-transitions/dissolve/index.html
index bc03cc22..67c95214 100644
--- a/animations/03-page-transitions/dissolve/index.html
+++ b/animations/03-page-transitions/dissolve/index.html
@@ -65,7 +65,7 @@
.log-row{font-size:9px;color:var(--ui-muted)}
button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}.nav-btn:hover{border-color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}.stage{flex:none;width:100%}aside{width:100%}.nav-btn,button.rst{min-height:44px}:root{--stage-h:480px}}
@media(prefers-reduced-motion:reduce){.page{transition:opacity 300ms linear}.dtile{transition:none!important}}
</style>
<style id="ah-inject">
@@ -153,10 +153,10 @@ body{padding-top:46px}
if(style==='diagonal'){
return Array.from({length:total},(_,i)=>{const r=Math.floor(i/n),c=i%n;return(r+c)/(2*(n-1))});
}
- // radial from center
+ // radial from center: tile-centre distance, normalised so the corners land at 1
return Array.from({length:total},(_,i)=>{
- const r=Math.floor(i/n)-n/2,c=i%n-n/2;
- const d=Math.sqrt(r*r+c*c)/Math.sqrt(2)*n/2;return d/(n*0.8);
+ const r=Math.floor(i/n)-(n-1)/2,c=i%n-(n-1)/2;
+ return Math.sqrt(r*r+c*c)/(Math.SQRT2*(n-1)/2);
});
}
@@ -167,7 +167,8 @@ body{padding-top:46px}
const showMask=maskTog.checked;
Array.from({length:n*n},(_,i)=>{
const t=document.createElement('div');t.className='dtile';
- t.style.cssText=`background:${bg};opacity:0;transition:opacity ${Math.round(tileDur*0.6)}ms ease ${Math.round(delays[i]*tileDur*0.7)}ms${showMask?';outline:1px solid rgba(255,100,100,.2)':''}`;
+ // stagger (33%) + per-tile fade (27%) = fully covered at 60%, when the swap fires
+ t.style.cssText=`background:${bg};opacity:0;transition:opacity ${Math.round(tileDur*0.27)}ms ease ${Math.round(delays[i]*tileDur*0.33)}ms${showMask?';outline:1px solid rgba(255,100,100,.2)':''}`;
overlay.appendChild(t);
});
return delays;
@@ -183,20 +184,21 @@ body{padding-top:46px}
function doDissolve(prev,next){
const o=document.getElementById('p'+prev),n=document.getElementById('p'+next);
const bg=getComputedStyle(o).background||'#060a10';
- buildTiles(gran,bg,dur);
+ const g=gran,d=dur; // freeze the settings for this run so mid-transition slider changes cannot desync the tiles
+ buildTiles(g,bg,d);
// Tiles appear over old page (dissolving it)
requestAnimationFrame(()=>requestAnimationFrame(()=>{
overlay.querySelectorAll('.dtile').forEach(t=>{t.style.opacity='1'});
- const swapAt=Math.round(dur*0.6);
+ const swapAt=Math.round(d*0.6);
setTimeout(()=>{
o.classList.remove('active');o.style.opacity='0';
n.classList.add('active');n.style.opacity='1';
if(biTog.checked){
- // Dissolve in: tiles fade back out
+ // Dissolve in: tiles fade back out over the remaining 40%
const tiles=[...overlay.querySelectorAll('.dtile')];
- const delays=getDelays(gran,styleSel.value);
- tiles.forEach((t,i)=>{t.style.transition=`opacity ${Math.round(dur*0.5)}ms ease ${Math.round(delays[i]*dur*0.6)}ms`;t.style.opacity='0'});
- setTimeout(()=>{overlay.innerHTML='';animating=false},dur+50);
+ const delays=getDelays(g,styleSel.value);
+ tiles.forEach((t,i)=>{t.style.transition=`opacity ${Math.round(d*0.18)}ms ease ${Math.round(delays[i]*d*0.22)}ms`;t.style.opacity='0'});
+ setTimeout(()=>{overlay.innerHTML='';animating=false},Math.round(d*0.4)+50);
}else{
overlay.innerHTML='';animating=false;
}
diff --git a/animations/03-page-transitions/elastic-transition/index.html b/animations/03-page-transitions/elastic-transition/index.html
index 06415f8e..107c10f7 100644
--- a/animations/03-page-transitions/elastic-transition/index.html
+++ b/animations/03-page-transitions/elastic-transition/index.html
@@ -63,7 +63,7 @@
.log-row{font-size:9px;color:var(--ui-muted)}
button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}.nav-btn:hover{border-color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}.nav-btn,.seg button,button.rst{min-height:44px}}
@media(prefers-reduced-motion:reduce){.page{transition:none!important;animation:none!important}}
</style>
<style id="kf-style"></style>
@@ -153,18 +153,18 @@ body{padding-top:46px}
function addLog(f,t){history.unshift(PAGES[f].name+' → '+PAGES[t].name);if(history.length>3)history.pop();logEl.innerHTML=history.map(l=>`<div class="log-row">${l}</div>`).join('')}
function buildKF(ov){
- const t=ov/100,os=1+t*0.15,un=1-t*0.06;
+ const t=ov/100,os=t,un=t;
kfStyle.textContent=`@keyframes elastic-in{
0%{transform:translateX(100%);opacity:0}
5%{opacity:1}
- 55%{transform:translateX(${-os*8}%)}
- 75%{transform:translateX(${un*2}%)}
- 88%{transform:translateX(-1%)}
+ 55%{transform:translateX(${-os*12}%)}
+ 75%{transform:translateX(${un*4}%)}
+ 88%{transform:translateX(${-t*1.5}%)}
100%{transform:translateX(0);opacity:1}
}
@keyframes elastic-out{
0%{transform:translateX(0);opacity:1}
- 40%{transform:translateX(${os*5}%)}
+ 40%{transform:translateX(${os*6}%)}
100%{transform:translateX(-100%);opacity:0}
}`;
}
@@ -197,7 +197,7 @@ body{padding-top:46px}
o.style.transition=`transform 300ms ease-in, opacity 300ms ease-in`;
o.style.transform='translateX(-40%)';o.style.opacity='0';
// Spring in new page from right
- let pos=-100,vel=0,target=0;
+ let pos=100,vel=0,target=0;
n.style.opacity='1';n.style.transform=`translateX(${pos}%)`;n.classList.add('active');
const positions=[];
let rafId,lastTime=null;
diff --git a/animations/03-page-transitions/flash-transition/index.html b/animations/03-page-transitions/flash-transition/index.html
index 82bbd823..41fd4f8c 100644
--- a/animations/03-page-transitions/flash-transition/index.html
+++ b/animations/03-page-transitions/flash-transition/index.html
@@ -35,8 +35,8 @@
.nav-btn{background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:var(--mono);font-size:10px;padding:6px 14px;border-radius:4px;cursor:pointer;min-height:36px}
.nav-btn.active{border-color:var(--ui-accent);color:var(--ui-accent)}
.page-area{flex:1;position:relative;overflow:hidden}
- .page{position:absolute;inset:0;pointer-events:none}
- .page.active{pointer-events:auto}
+ .page{position:absolute;inset:0;pointer-events:none;visibility:hidden}
+ .page.active{pointer-events:auto;visibility:visible}
/* Flash overlay */
#flash-overlay{position:absolute;inset:0;background:var(--flash-color);opacity:0;pointer-events:none;z-index:10;filter:blur(0)}
#flash-overlay.blur-on{filter:blur(8px)}
@@ -51,6 +51,7 @@
.pstat span{font-size:9px;opacity:.4;text-transform:uppercase;letter-spacing:1px}
/* timeline */
#tl{display:flex;gap:4px;align-items:center;margin-top:4px}
+ #tl>div{flex:1;min-width:0}
.tl-seg{flex:1;height:4px;border-radius:2px;background:var(--ui-border)}
.tl-seg.on{background:var(--ui-accent)}
.tl-lbl{font-size:8px;color:var(--ui-muted);text-align:center;margin-top:2px}
@@ -70,9 +71,9 @@
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
.log{display:flex;flex-direction:column;gap:2px}
.log-row{font-size:9px;color:var(--ui-muted)}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}.nav-btn:hover{border-color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}.stage{flex:0 0 auto;width:100%}aside{width:100%}:root{--stage-h:480px}.nav-btn{min-height:44px}.sw{width:44px;height:44px}}
@media(prefers-reduced-motion:reduce){#flash-overlay{display:none}}
</style>
<style id="ah-inject">
@@ -189,10 +190,13 @@ body{padding-top:46px}
},flashIn);
}
- document.querySelectorAll('.sw').forEach(s=>s.addEventListener('click',()=>{
- document.querySelectorAll('.sw').forEach(x=>x.classList.remove('on'));s.classList.add('on');
- document.documentElement.style.setProperty('--flash-color',s.dataset.c);
- }));
+ document.querySelectorAll('.sw').forEach(s=>{
+ s.addEventListener('click',()=>{
+ document.querySelectorAll('.sw').forEach(x=>x.classList.remove('on'));s.classList.add('on');
+ document.documentElement.style.setProperty('--flash-color',s.dataset.c);
+ });
+ s.addEventListener('keydown',e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();s.click();}});
+ });
inSl.addEventListener('input',()=>{flashIn=+inSl.value;inV.textContent=flashIn+'ms'});
outSl.addEventListener('input',()=>{flashOut=+outSl.value;outV.textContent=flashOut+'ms'});
intSl.addEventListener('input',()=>{intensity=intSl.value/100;intV.textContent=intensity.toFixed(2)});
diff --git a/animations/03-page-transitions/flip-technique/index.html b/animations/03-page-transitions/flip-technique/index.html
index 1575f271..d8341a96 100644
--- a/animations/03-page-transitions/flip-technique/index.html
+++ b/animations/03-page-transitions/flip-technique/index.html
@@ -33,7 +33,7 @@
.stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:var(--bg);overflow:hidden;display:flex;flex-direction:column}
.stage-toolbar{display:flex;gap:6px;padding:10px 12px;background:var(--ui-bg);border-bottom:1px solid var(--ui-border);flex-shrink:0;flex-wrap:wrap}
.tb-btn{background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:10px;padding:6px 12px;border-radius:4px;cursor:pointer;min-height:36px}
- .tb-btn:hover{border-color:var(--ui-accent);color:var(--ui-accent)}
+ @media(hover:hover){.tb-btn:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
.tb-btn.active-layout{border-color:var(--ui-accent);color:var(--ui-accent)}
.page-area{flex:1;position:relative;overflow:hidden;padding:16px}
#card-grid{display:grid;gap:10px;transition:none}
@@ -56,9 +56,9 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}.stage{height:auto;min-height:var(--stage-h)}.tb-btn{min-height:44px}}
@media(prefers-reduced-motion:reduce){.flip-card{transition:none!important}}
</style>
<style id="ah-inject">
@@ -187,6 +187,7 @@ body{padding-top:46px}
document.getElementById('btn-color').addEventListener('click',()=>doFlip([...order].sort((a,b)=>CARDS[a].colorRank-CARDS[b].colorRank)));
document.getElementById('btn-size').addEventListener('click',()=>doFlip([...order].sort((a,b)=>CARDS[b].h-CARDS[a].h)));
document.querySelectorAll('[data-cols]').forEach(b=>b.addEventListener('click',()=>{
+ if(animating)return;
const c=+b.dataset.cols;
document.querySelectorAll('[data-cols]').forEach(x=>x.classList.remove('active-layout'));b.classList.add('active-layout');
const labels={1:'List',2:'2 columns',3:'3 columns'};layoutVal.textContent=labels[c];
diff --git a/animations/03-page-transitions/morph-transition/index.html b/animations/03-page-transitions/morph-transition/index.html
index 2601ded8..7df6a53d 100644
--- a/animations/03-page-transitions/morph-transition/index.html
+++ b/animations/03-page-transitions/morph-transition/index.html
@@ -34,7 +34,7 @@
.mini-nav{display:flex;gap:6px;padding:10px 12px;background:var(--ui-bg);border-bottom:1px solid var(--ui-border);flex-shrink:0;align-items:center}
.nav-logo{flex-shrink:0;margin-right:8px}
.nav-logo svg{display:block}
- .nav-btn{background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:var(--mono);font-size:10px;padding:6px 14px;border-radius:4px;cursor:pointer;min-height:36px}
+ .nav-btn{background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:var(--mono);font-size:10px;padding:6px 14px;border-radius:4px;cursor:pointer;min-height:44px}
.nav-btn.active{border-color:var(--ui-accent);color:var(--ui-accent)}
.page-area{flex:1;position:relative;overflow:hidden}
.page{position:absolute;inset:0;opacity:0;pointer-events:none;transition:opacity 300ms ease}
@@ -49,7 +49,7 @@
.pstat b{display:block;font-size:clamp(18px,2.5vw,24px);color:#58a6ff}
.pstat span{font-size:9px;opacity:.4;text-transform:uppercase;letter-spacing:1px}
.shape-row{display:flex;gap:8px;margin-top:4px}
- .shape-btn{background:none;border:1px solid var(--ui-border);padding:6px;border-radius:4px;cursor:pointer;flex-shrink:0}
+ .shape-btn{background:none;border:1px solid var(--ui-border);padding:6px;border-radius:4px;cursor:pointer;flex-shrink:0;min-width:44px;min-height:44px;display:flex;align-items:center;justify-content:center}
.shape-btn.on{border-color:var(--ui-accent)}
.shape-btn svg{display:block}
.pts-overlay{position:absolute;top:0;left:0;pointer-events:none;opacity:0;transition:opacity .2s}
@@ -68,9 +68,10 @@
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
.log{display:flex;flex-direction:column;gap:2px}
.log-row{font-size:9px;color:var(--ui-muted)}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}.nav-btn:hover{border-color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}}
+ @media(prefers-reduced-motion:reduce){.page,.pts-overlay{transition:none}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -170,16 +171,18 @@ body{padding-top:46px}
morphPath.setAttribute('d',pts2path(circle12));morphPath.setAttribute('fill',SHAPES[0].color);
function lerp(a,b,t){return a+(b-a)*t}
- function easeFn(t){const e=easeSel.value;if(e==='linear')return t;if(e==='ease-out')return 1-(1-t)**3;if(e==='springy'){const ov=1.2;return t<0.5?2*t*t:(t<0.8?ov-(ov-1)*(t-0.5)/0.3:1);}return t<0.5?2*t*t:1-(-2*t+2)**2/2}
+ function easeFn(t,e=easeSel.value){if(e==='linear')return t;if(e==='ease-out')return 1-(1-t)**3;if(e==='springy'){const ov=1.2;return t<0.5?ov*(1-(1-2*t)**2):(t<0.8?ov-(ov-1)*(t-0.5)/0.3:1);}return t<0.5?2*t*t:1-(-2*t+2)**2/2}
+ function render(pts){morphPath.setAttribute('d',pts2path(pts));currentPts=pts;if(ptsTog.checked)drawPts(pts);}
function startMorph(from,to,done){
if(morphRaf)cancelAnimationFrame(morphRaf);
- const start=performance.now();
+ morphRaf=null;
+ if(!motionOk){render([...to]);done?.();return;}
+ const start=performance.now(),d=dur,ez=easeSel.value;
function tick(now){
- const t=Math.min((now-start)/dur,1),et=easeFn(t);
- const pts=from.map(([ax,ay],i)=>[lerp(ax,to[i][0],et),lerp(ay,to[i][1],et)]);
- morphPath.setAttribute('d',pts2path(pts));
- if(t<1)morphRaf=requestAnimationFrame(tick);else{done?.();morphRaf=null;}
+ const t=Math.min((now-start)/d,1),et=easeFn(t,ez);
+ render(from.map(([ax,ay],i)=>[lerp(ax,to[i][0],et),lerp(ay,to[i][1],et)]));
+ if(t<1)morphRaf=requestAnimationFrame(tick);else{morphRaf=null;done?.();}
}
morphRaf=requestAnimationFrame(tick);
}
@@ -193,8 +196,7 @@ body{padding-top:46px}
// Crossfade pages
document.getElementById('p'+prev).classList.remove('active');
document.getElementById('p'+next).classList.add('active');
- if(!motionOk)return;
- // Morph the logo shape
+ // Morph the logo shape (snaps straight to the target under reduced motion)
const targetShape=SHAPES[PAGES[next].shape];
animating=true;
startMorph(currentPts,targetShape.pts,()=>{
@@ -207,19 +209,19 @@ body{padding-top:46px}
const NS='http://www.w3.org/2000/svg';
let ptsGroup=null;
+ function drawPts(pts){
+ if(!ptsGroup){ptsGroup=document.createElementNS(NS,'g');ptsGroup.id='pts-g';document.getElementById('morph-svg').appendChild(ptsGroup);}
+ ptsGroup.innerHTML=pts.map(([x,y])=>`<circle cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="3" fill="#58a6ff" opacity=".9"/>`).join('');
+ }
ptsTog.addEventListener('change',()=>{
morphPath.style.opacity=ptsTog.checked?'0.5':'';
- const svg=document.getElementById('morph-svg');
- if(ptsTog.checked){
- if(!ptsGroup){ptsGroup=document.createElementNS(NS,'g');ptsGroup.id='pts-g';svg.appendChild(ptsGroup);}
- ptsGroup.innerHTML=currentPts.map(([x,y])=>`<circle cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="3" fill="#58a6ff" opacity=".9"/>`).join('');
- }else if(ptsGroup){ptsGroup.innerHTML='';}
+ if(ptsTog.checked)drawPts(currentPts);else if(ptsGroup)ptsGroup.innerHTML='';
});
durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms'});
document.getElementById('rst-btn').addEventListener('click',()=>{
if(animating)return;const p=current;current=0;updateNav(0);if(p!==0)addLog(p,0);
document.querySelectorAll('.page').forEach((el,i)=>el.classList.toggle('active',i===0));
- if(motionOk)startMorph(currentPts,circle12,()=>{currentPts=[...circle12];shapeVal.textContent='Circle';morphPath.setAttribute('fill',SHAPES[0].color);document.querySelectorAll('.shape-btn').forEach((x,j)=>x.classList.toggle('on',j===0));animating=false;});
+ startMorph(currentPts,circle12,()=>{currentPts=[...circle12];shapeVal.textContent='Circle';morphPath.setAttribute('fill',SHAPES[0].color);document.querySelectorAll('.shape-btn').forEach((x,j)=>x.classList.toggle('on',j===0));animating=false;});
});
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/03-page-transitions/portal-zoom/index.html b/animations/03-page-transitions/portal-zoom/index.html
index d394f5b0..de069e8f 100644
--- a/animations/03-page-transitions/portal-zoom/index.html
+++ b/animations/03-page-transitions/portal-zoom/index.html
@@ -68,7 +68,7 @@
.log-row{font-size:9px;color:var(--ui-muted)}
button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}.nav-btn:hover{border-color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}.nav-btn,button.rst{min-height:44px}:root{--stage-h:480px}}
@media(prefers-reduced-motion:reduce){#zoom-mask{transition:none!important}}
</style>
<style id="ah-inject">
@@ -181,7 +181,7 @@ body{padding-top:46px}
const isSquare=shapeSel.value==='square';
const startClip=isSquare?`inset(${py} ${(100-parseFloat(px)).toFixed(1)}% ${(100-parseFloat(py)).toFixed(1)}% ${px})`:`circle(0% at ${px} ${py})`;
const endClip=isSquare?'inset(0%)':`circle(150% at ${px} ${py})`;
- nextEl.style.clipPath=startClip;
+ nextEl.style.clipPath=startClip;nextEl.style.zIndex='2'; // incoming page must paint above the outgoing one regardless of DOM order
nextEl.style.transition='none';
nextEl.classList.add('active');
nextEl.offsetHeight; // force reflow
@@ -189,7 +189,7 @@ body{padding-top:46px}
nextEl.style.clipPath=endClip;
setTimeout(()=>{
prevEl.classList.remove('active');
- nextEl.style.clipPath='';nextEl.style.transition='';
+ nextEl.style.clipPath='';nextEl.style.transition='';nextEl.style.zIndex='';
animating=false;
},dur+50);
}
diff --git a/animations/03-page-transitions/shared-element-transition/index.html b/animations/03-page-transitions/shared-element-transition/index.html
index 68f91a79..d183150f 100644
--- a/animations/03-page-transitions/shared-element-transition/index.html
+++ b/animations/03-page-transitions/shared-element-transition/index.html
@@ -63,9 +63,9 @@
.sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
.sv{width:38px;text-align:right;color:var(--ui-text)}
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}#page-grid{grid-template-columns:1fr 1fr}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}#page-grid{grid-template-columns:1fr 1fr}.nav-back{min-height:44px}}
@media(prefers-reduced-motion:reduce){#flip-el{transition:none!important}}
</style>
<style id="ah-inject">
@@ -163,7 +163,7 @@ body{padding-top:46px}
// LAST: show detail to get hero rect
detail.classList.add('active');
const heroRect=detailHero.getBoundingClientRect();
- if(!motionOk){navBack.classList.add('show');navTitle.textContent=p.name;grid.style.opacity='0';grid.style.pointerEvents='none';animating=false;return;}
+ if(!motionOk){detail.style.transition='none';detail.style.opacity='1';navBack.classList.add('show');navTitle.textContent=p.name;grid.style.opacity='0';grid.style.pointerEvents='none';currentView='detail';animating=false;return;}
// FLIP: animate the shared element
flipEl.style.cssText=`background:${p.bg};border-radius:10px;width:${thumbRect.width}px;height:${thumbRect.height}px;top:${thumbRect.top}px;left:${thumbRect.left}px;transition:none;display:block`;
grid.style.opacity='0';grid.style.transition=`opacity ${Math.round(dur*0.4)}ms ease`;
diff --git a/animations/03-page-transitions/slide-transition/index.html b/animations/03-page-transitions/slide-transition/index.html
index 34a3dc6e..dd037322 100644
--- a/animations/03-page-transitions/slide-transition/index.html
+++ b/animations/03-page-transitions/slide-transition/index.html
@@ -58,9 +58,9 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.log{display:flex;flex-direction:column;gap:2px}
.log-row{font-size:9px;color:var(--ui-muted)}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}.nav-btn:hover{border-color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}.stage{flex:none}.nav-btn{min-height:44px}aside{width:100%}:root{--stage-h:480px}}
@media(prefers-reduced-motion:reduce){.page{transition:none!important}}
</style>
<style id="ah-inject">
@@ -159,7 +159,7 @@ body{padding-top:46px}
if(next===current||animating)return;
const prev=current;current=next;
updateNav(next);addLog(prev,next);
- if(!motionOk){document.querySelectorAll('.page').forEach((el,i)=>{el.classList.toggle('active',i===next);el.style.transform=''});return;}
+ if(!motionOk){dirVal.textContent='—';document.querySelectorAll('.page').forEach((el,i)=>{el.classList.toggle('active',i===next);el.style.transform=i===next?'':'translateX(100%)'});return;}
animating=true;doTransition(prev,next);
}
@@ -169,7 +169,7 @@ body{padding-top:46px}
const axis=Math.abs(d)===2?'Y':'X';
const sign=d<0?-1:1;
const dir=axis==='Y'?'Y':'X';
- dirVal.textContent=d<0?'← slide left':d>0?'→ slide right':'↓ slide down';
+ dirVal.textContent=axis==='Y'?'↓ slide down':d<0?'← slide left':'→ slide right';
// Position new page off-screen
newEl.style.transition='none';newEl.style.transform=`translate${dir}(${sign*-100}%)`;newEl.style.pointerEvents='none';
requestAnimationFrame(()=>requestAnimationFrame(()=>{
@@ -193,7 +193,7 @@ body{padding-top:46px}
durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms'});
stagSl.addEventListener('input',()=>{stagger=+stagSl.value;stagV.textContent=stagger+'ms'});
document.getElementById('rst-btn').addEventListener('click',()=>{
- if(animating)return;const p=current;current=0;updateNav(0);if(p!==0)addLog(p,0);
+ if(animating)return;const p=current;current=0;updateNav(0);if(p!==0)addLog(p,0);dirVal.textContent='—';
document.querySelectorAll('.page').forEach((el,i)=>{el.classList.toggle('active',i===0);el.style.transform=i===0?'':'translateX(100%)';el.style.transition=''});animating=false;
});
</script>
diff --git a/animations/03-page-transitions/view-transitions-api/index.html b/animations/03-page-transitions/view-transitions-api/index.html
index 2dc65ae6..6813229e 100644
--- a/animations/03-page-transitions/view-transitions-api/index.html
+++ b/animations/03-page-transitions/view-transitions-api/index.html
@@ -32,13 +32,15 @@
.layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
.stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:var(--bg);overflow:hidden;display:flex;flex-direction:column}
.mini-nav{display:flex;gap:6px;padding:10px 12px;background:var(--ui-bg);border-bottom:1px solid var(--ui-border);flex-shrink:0}
- .nav-btn{background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:var(--mono);font-size:10px;padding:6px 14px;border-radius:4px;cursor:pointer;min-height:36px}
+ .nav-btn{background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:var(--mono);font-size:10px;padding:6px 14px;border-radius:4px;cursor:pointer;min-height:44px}
.nav-btn.active{border-color:var(--ui-accent);color:var(--ui-accent)}
.page-area{flex:1;position:relative;overflow:hidden;view-transition-name:page-content}
.page{position:absolute;inset:0;pointer-events:none}
.page.active{pointer-events:auto}
/* Suppress root animation — we only want page-content to animate */
::view-transition-old(root),::view-transition-new(root){animation:none}
+ /* Keep the sliding/scaling snapshots inside the stage instead of bleeding over the page */
+ ::view-transition-group(page-content){overflow:clip}
/* Default: crossfade */
::view-transition-old(page-content){animation:vt-out var(--vt-dur) var(--vt-ease) both}
::view-transition-new(page-content){animation:vt-in var(--vt-dur) var(--vt-ease) both}
@@ -83,9 +85,9 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.log{display:flex;flex-direction:column;gap:2px}
.log-row{font-size:9px;color:var(--ui-muted)}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}.nav-btn:hover{border-color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}.stage{flex:none}aside{width:100%}:root{--stage-h:480px}}
@media(prefers-reduced-motion:reduce){::view-transition-old(page-content),::view-transition-new(page-content){animation:none}}
</style>
<style id="ah-inject">
@@ -183,6 +185,7 @@ body{padding-top:46px}
document.documentElement.dataset.vt=style==='crossfade'?'':style;
if(supportsVT){
const t=document.startViewTransition(()=>switchPage(prev,next));
+ t.ready.catch(()=>{}); // a skipped transition (e.g. tab hidden) rejects ready; the DOM change still applies
await t.finished;
}else{
// Fallback crossfade
diff --git a/animations/03-page-transitions/zoom-transition/index.html b/animations/03-page-transitions/zoom-transition/index.html
index 87e90004..eb81e230 100644
--- a/animations/03-page-transitions/zoom-transition/index.html
+++ b/animations/03-page-transitions/zoom-transition/index.html
@@ -63,7 +63,7 @@
.log-row{font-size:9px;color:var(--ui-muted)}
button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}.nav-btn:hover{border-color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}.nav-btn,.seg button,button.rst{min-height:44px}:root{--stage-h:480px}}
@media(prefers-reduced-motion:reduce){.page{transition:none!important}}
</style>
<style id="ah-inject">
@@ -96,7 +96,7 @@ body{padding-top:46px}
<div class="lbl">State</div>
<div class="kv"><span>Page</span><span class="v" id="cur-page">Home</span></div>
<div class="kv"><span>Old scale</span><span class="v" id="sc-old">1.00</span></div>
- <div class="kv"><span>New scale</span><span class="v" id="sc-new">0.80</span></div>
+ <div class="kv"><span>New scale</span><span class="v" id="sc-new">1.00</span></div>
<div class="div"></div>
<div class="lbl">Variant</div>
<div class="seg" id="var-seg">
@@ -135,7 +135,6 @@ body{padding-top:46px}
const easeSel=document.getElementById('ease-sel');
let current=0,animating=false,dur=550,variant='zoom-in',history=[];
const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
- let rafId=null;
PAGES.forEach((p,i)=>{
const d=document.createElement('div');d.className='page'+(i===0?' active':'');d.id='p'+i;d.style.background=p.bg;d.innerHTML=p.html;d.style.opacity=i===0?'1':'0';area.appendChild(d);
@@ -152,12 +151,6 @@ body{padding-top:46px}
animating=true;doTransition(prev,next);
}
- function trackScales(oldEl,newEl){
- scOld.textContent=parseFloat(getComputedStyle(oldEl).getPropertyValue('transform')!=='none'?'..':'1').toFixed?.(2)||'1.00';
- scNew.textContent='...';
- rafId=requestAnimationFrame(()=>trackScales(oldEl,newEl));
- }
-
function doTransition(prev,next){
const o=document.getElementById('p'+prev),n=document.getElementById('p'+next);
const ease=easeSel.value,t=`all ${dur}ms ${ease}`;
diff --git a/animations/04-micro-interactions/accordion/index.html b/animations/04-micro-interactions/accordion/index.html
index 9d7d058a..72664880 100644
--- a/animations/04-micro-interactions/accordion/index.html
+++ b/animations/04-micro-interactions/accordion/index.html
@@ -30,8 +30,8 @@
header h1{font-family:var(--disp);font-weight:700;font-size:clamp(11px,1.8vw,15px);letter-spacing:-.01em}
header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
.layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:var(--bg);display:flex;align-items:center;justify-content:center;padding:24px;overflow:hidden}
- .acc-list{width:100%;max-width:420px;display:flex;flex-direction:column;gap:4px}
+ .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:var(--bg);display:flex;align-items:flex-start;justify-content:center;padding:24px;overflow:auto}
+ .acc-list{width:100%;max-width:420px;margin:auto;display:flex;flex-direction:column;gap:4px}
/* Accordion item */
.acc-item{background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:6px;overflow:hidden;transition:border-color .15s}
.acc-item.open{border-color:rgba(255,157,92,.35)}
@@ -45,7 +45,8 @@
/* CSS grid method */
.acc-body.grid-method{display:grid;grid-template-rows:0fr;transition:grid-template-rows var(--acc-dur) var(--acc-ease)}
.acc-body.grid-method.open{grid-template-rows:1fr}
- .acc-inner{overflow:hidden;padding:0 16px 16px;font-size:11px;color:var(--ui-muted);line-height:1.7}
+ .acc-inner{overflow:hidden;min-height:0;padding:0 16px;font-size:11px;color:var(--ui-muted);line-height:1.7}
+ .acc-inner > :last-child{padding-bottom:16px}
/* Stagger children */
.acc-body.stagger .acc-inner > *{opacity:0;transform:translateY(4px);transition:opacity .2s ease,transform .2s ease}
.acc-body.stagger.open .acc-inner > *{opacity:1;transform:translateY(0)}
@@ -173,15 +174,19 @@ body{padding-top:46px}
body.classList.add('open');
}
openSet.add(item);
- if(document.getElementById('stagger-tog').checked)body.classList.add('stagger');
updateCount();
}
function closeItem(item){
const body=getBody(item);const trigger=getTrigger(item);
item.classList.remove('open');trigger.setAttribute('aria-expanded','false');
- body.classList.remove('open','stagger');
+ body.classList.remove('open');
openSet.delete(item);updateCount();
}
+ // Stagger class must already be on the body before .open is added, so children start at opacity 0
+ function applyStagger(){
+ const on=document.getElementById('stagger-tog').checked;
+ items.forEach(item=>getBody(item).classList.toggle('stagger',on));
+ }
function toggle(item){
const isOpen=openSet.has(item);
if(!multiOpen)openSet.forEach(i=>{if(i!==item)closeItem(i)});
@@ -200,7 +205,13 @@ body{padding-top:46px}
const body=getBody(item);
body.className='acc-body '+(m==='js'?'js-method':'grid-method');
});
+ applyStagger();
}
+ // JS method: re-measure open items when the viewport changes so content isn't clipped
+ addEventListener('resize',()=>{
+ if(method!=='js')return;
+ openSet.forEach(item=>{const body=getBody(item);body.style.setProperty('--target-h',body.querySelector('.acc-inner').scrollHeight+'px')});
+ });
document.getElementById('method-sel').addEventListener('change',e=>switchMethod(e.target.value));
document.getElementById('dur-sl').addEventListener('input',e=>{
@@ -212,10 +223,9 @@ body{padding-top:46px}
});
document.getElementById('multi-tog').addEventListener('change',e=>{multiOpen=e.target.checked});
document.getElementById('chevron-tog').addEventListener('change',e=>{
- document.querySelectorAll('.acc-chevron').forEach(c=>{
- c.style.transition=e.target.checked?`transform var(--acc-dur) var(--acc-ease)`:'none';
- });
+ document.querySelectorAll('.acc-chevron').forEach(c=>{c.style.transform=e.target.checked?'':'none'});
});
+ document.getElementById('stagger-tog').addEventListener('change',applyStagger);
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
</body>
diff --git a/animations/04-micro-interactions/badge-pulse/index.html b/animations/04-micro-interactions/badge-pulse/index.html
index 94f87438..fe34f1d7 100644
--- a/animations/04-micro-interactions/badge-pulse/index.html
+++ b/animations/04-micro-interactions/badge-pulse/index.html
@@ -51,7 +51,7 @@
.pulse-both .badge,.pulse-both .dot-badge{animation:badge-scale var(--pulse-dur) ease-in-out infinite}
.pulse-both .badge::after,.pulse-both .dot-badge::after{content:'';position:absolute;inset:-4px;border-radius:50%;background:var(--badge-color);opacity:.4;animation:halo-grow var(--pulse-dur) ease-out infinite}
/* Fade mode */
- .fade-mode .badge,.fade-mode .dot-badge{animation-iteration-count:3!important}
+ .fade-mode .badge,.fade-mode .dot-badge,.fade-mode .badge::after,.fade-mode .dot-badge::after{animation-iteration-count:3!important}
/* Status dot (online) */
.status-dot{position:absolute;bottom:-2px;right:-2px;width:16px;height:16px;border-radius:50%;background:#56d364;border:2px solid var(--bg);animation:badge-scale var(--pulse-dur) ease-in-out infinite}
/* Panel */
@@ -65,9 +65,9 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:360px}.icon-row{gap:20px}}
- @media(prefers-reduced-motion:reduce){.badge,.dot-badge,.status-dot,.badge::after,.dot-badge::after{animation:none!important}}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:360px}.icon-row{gap:20px}}
+ @media(prefers-reduced-motion:reduce){.badge,.dot-badge,.status-dot,.badge::after,.dot-badge::after{animation:none!important}.badge::after,.dot-badge::after{display:none}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -143,15 +143,18 @@ body{padding-top:46px}
icons.forEach((ic,i)=>{
if(i===2)return; // status dot always pulses
ic.classList.remove('pulse-scale','pulse-halo','pulse-both');
+ void ic.offsetWidth; // reflow so re-adding the same class restarts the animation
ic.classList.add(currentStyle);
});
}
icons.forEach((ic,i)=>{
- ic.addEventListener('click',()=>{
+ const dismiss=()=>{
const b=ic.querySelector('.badge,.dot-badge');
if(b){b.style.display='none';}
- });
+ };
+ ic.addEventListener('click',dismiss);
+ ic.addEventListener('keydown',e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();dismiss();}});
});
document.getElementById('dur-sl').addEventListener('input',e=>{
@@ -171,6 +174,7 @@ body{padding-top:46px}
});
document.getElementById('fade-tog').addEventListener('change',e=>{
icons.forEach(ic=>ic.classList.toggle('fade-mode',e.target.checked));
+ if(e.target.checked)applyStyle(); // restart so the 3-pulse run is visible each time
});
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/04-micro-interactions/button-press-scale/index.html b/animations/04-micro-interactions/button-press-scale/index.html
index b4f7c957..92c63cd6 100644
--- a/animations/04-micro-interactions/button-press-scale/index.html
+++ b/animations/04-micro-interactions/button-press-scale/index.html
@@ -51,7 +51,7 @@
.sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
.sv{width:44px;text-align:right;color:var(--ui-text)}
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:360px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:360px}}
@media(prefers-reduced-motion:reduce){.pbtn,.pbtn.pressed{transition:none!important}}
</style>
<style id="ah-inject">
@@ -112,12 +112,13 @@ body{padding-top:46px}
btns.forEach((btn,i)=>{
const press=()=>btn.classList.add('pressed');
const release=()=>{
+ if(!btn.classList.contains('pressed'))return;
btn.classList.remove('pressed');
counts[i]++;total++;
document.getElementById('c'+i).textContent=counts[i];
document.getElementById('total').textContent=total;
};
- btn.addEventListener('pointerdown',press);
+ btn.addEventListener('pointerdown',e=>{press();btn.setPointerCapture(e.pointerId)});
btn.addEventListener('pointerup',release);
btn.addEventListener('pointercancel',()=>btn.classList.remove('pressed'));
btn.addEventListener('keydown',e=>{if(e.key===' '||e.key==='Enter')press()});
diff --git a/animations/04-micro-interactions/checkmark-draw/index.html b/animations/04-micro-interactions/checkmark-draw/index.html
index 43716205..daf62e19 100644
--- a/animations/04-micro-interactions/checkmark-draw/index.html
+++ b/animations/04-micro-interactions/checkmark-draw/index.html
@@ -42,7 +42,7 @@
/* SVG icon container */
.icon-wrap{width:80px;height:80px;position:relative}
.icon-wrap svg{width:100%;height:100%}
- .check-circle{fill:none;stroke:var(--stroke-color);stroke-width:var(--stroke-w);stroke-dasharray:188;stroke-dashoffset:188;transition:stroke-dashoffset var(--draw-dur) var(--draw-ease)}
+ .check-circle{fill:none;stroke:var(--stroke-color);stroke-width:var(--stroke-w);stroke-dasharray:189;stroke-dashoffset:189;transition:stroke-dashoffset var(--draw-dur) var(--draw-ease)}
.check-mark{fill:none;stroke:var(--stroke-color);stroke-width:var(--stroke-w);stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:52;stroke-dashoffset:52;transition:stroke-dashoffset var(--draw-dur) var(--draw-ease)}
.icon-wrap.drawn .check-circle{stroke-dashoffset:0}
.icon-wrap.drawn .check-mark{stroke-dashoffset:0;transition-delay:calc(var(--draw-dur)*0.4)}
@@ -66,11 +66,11 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:440px}}
- @media(prefers-reduced-motion:reduce){.check-circle,.check-mark,.x-mark,.x-mark2{transition:none!important}.icon-wrap.drawn .check-circle,.icon-wrap.drawn .check-mark,.icon-wrap.error .x-mark,.icon-wrap.error .x-mark2{stroke-dashoffset:0}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:440px}}
+ @media(prefers-reduced-motion:reduce){.check-circle,.check-mark,.x-mark,.x-mark2{transition:none!important}.icon-wrap.drawn .check-circle,.icon-wrap.drawn .check-mark,.icon-wrap.error .x-mark,.icon-wrap.error .x-mark2{stroke-dashoffset:0}.icon-wrap.shake{animation:none}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -135,9 +135,10 @@ body{padding-top:46px}
const btnCheck=document.getElementById('btn-check');
const iconWrap=document.getElementById('icon-wrap');
const stateLabel=document.getElementById('state-label');
- let running=false,autoTimer=null;
+ let running=false,autoTimer=null,seqTimer=null;
function reset(){
+ clearTimeout(seqTimer);running=false;
iconWrap.classList.remove('drawn','error','shake');
btn.disabled=false;btn.style.background='';
btnText.style.opacity='1';btnSpin.style.opacity='0';btnCheck.style.opacity='0';
@@ -150,7 +151,7 @@ body{padding-top:46px}
stateLabel.textContent='Loading…';
btnText.style.opacity='0';btnSpin.style.opacity='1';
const showError=document.getElementById('error-tog').checked;
- setTimeout(()=>{
+ seqTimer=setTimeout(()=>{
btnSpin.style.opacity='0';btnCheck.style.opacity='1';
if(showError){
btn.style.background='#f85149';
diff --git a/animations/04-micro-interactions/click-ripple/index.html b/animations/04-micro-interactions/click-ripple/index.html
index d31997b2..6c0cb50f 100644
--- a/animations/04-micro-interactions/click-ripple/index.html
+++ b/animations/04-micro-interactions/click-ripple/index.html
@@ -52,7 +52,7 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:380px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:380px}}
/* Reduced motion: collapse the ripple to near-instant (keep animationend cleanup firing) */
@media(prefers-reduced-motion:reduce){.ripple{animation-duration:1ms!important}.rbtn{transition:none!important}}
</style>
diff --git a/animations/04-micro-interactions/copy-to-clipboard/index.html b/animations/04-micro-interactions/copy-to-clipboard/index.html
index 09e6ac76..a91e1147 100644
--- a/animations/04-micro-interactions/copy-to-clipboard/index.html
+++ b/animations/04-micro-interactions/copy-to-clipboard/index.html
@@ -136,10 +136,7 @@ el.animate(
let timer=null;
let revert=1500;
- function copyText(text){
- if(navigator.clipboard&&navigator.clipboard.writeText){
- return navigator.clipboard.writeText(text);
- }
+ function legacyCopy(text){
return new Promise((res,rej)=>{
const ta=document.createElement('textarea');
ta.value=text;ta.style.position='fixed';ta.style.opacity='0';
@@ -148,6 +145,13 @@ el.animate(
document.body.removeChild(ta);
});
}
+ function copyText(text){
+ if(navigator.clipboard&&navigator.clipboard.writeText){
+ // the API can exist yet reject (permission denied, embedded frame) — fall back then too
+ return navigator.clipboard.writeText(text).catch(()=>legacyCopy(text));
+ }
+ return legacyCopy(text);
+ }
btn.addEventListener('click',()=>{
const text=snippet.innerText;
diff --git a/animations/04-micro-interactions/cursor-follower/index.html b/animations/04-micro-interactions/cursor-follower/index.html
index 7c88687e..9ff15a10 100644
--- a/animations/04-micro-interactions/cursor-follower/index.html
+++ b/animations/04-micro-interactions/cursor-follower/index.html
@@ -40,7 +40,7 @@
/* Hover targets */
.hover-target{padding:10px 18px;border-radius:6px;border:1px solid var(--ui-border);cursor:none;font-size:11px;font-family:monospace;background:rgba(255,255,255,.05);transition:border-color .2s}
/* Cursor follower */
- #follower{position:absolute;pointer-events:none;z-index:100;transform:translate(-50%,-50%);will-change:transform;transition:width .2s ease,height .2s ease,border-radius .2s ease}
+ #follower{position:absolute;pointer-events:none;z-index:100;opacity:0;transform:translate(-50%,-50%);will-change:transform;transition:width .2s ease,height .2s ease,border-radius .2s ease}
#follower.circle{width:var(--follower-size);height:var(--follower-size);border-radius:50%;background:#fff;mix-blend-mode:difference}
#follower.ring{width:var(--follower-size);height:var(--follower-size);border-radius:50%;border:2px solid #fff;background:transparent;mix-blend-mode:difference}
#follower.square{width:var(--follower-size);height:var(--follower-size);border-radius:4px;background:#fff;mix-blend-mode:difference}
@@ -59,7 +59,7 @@
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
.kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
.kv .v{color:var(--ui-text)}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:400px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:400px}}
@media(prefers-reduced-motion:reduce){#follower{transition:none!important}}
</style>
<style id="ah-inject">
@@ -119,7 +119,13 @@ body{padding-top:46px}
const hasTouch=window.matchMedia('(pointer:coarse)').matches;
if(hasTouch){follower.style.display='none';}
- stage.addEventListener('mouseenter',()=>{inside=true;follower.style.opacity='1'});
+ stage.addEventListener('mouseenter',e=>{
+ // Snap to the entry point so the follower doesn't swoop in from its last position
+ const r=stage.getBoundingClientRect();
+ mx=fx=e.clientX-r.left;my=fy=e.clientY-r.top;
+ follower.style.left=fx.toFixed(1)+'px';follower.style.top=fy.toFixed(1)+'px';
+ inside=true;follower.style.opacity='1';
+ });
stage.addEventListener('mouseleave',()=>{inside=false;follower.style.opacity='0'});
stage.addEventListener('mousemove',e=>{
const r=stage.getBoundingClientRect();
@@ -152,13 +158,17 @@ body{padding-top:46px}
});
document.getElementById('shape-sel').addEventListener('change',e=>{
shape=e.target.value;
- follower.className=shape+(blend?'':' no-blend');
+ follower.classList.remove('circle','ring','square');
+ follower.classList.add(shape);
});
document.getElementById('blend-tog').addEventListener('change',e=>{
blend=e.target.checked;
follower.classList.toggle('no-blend',!blend);
});
- document.getElementById('expand-tog').addEventListener('change',e=>{expandOnHover=e.target.checked});
+ document.getElementById('expand-tog').addEventListener('change',e=>{
+ expandOnHover=e.target.checked;
+ if(!expandOnHover)follower.classList.remove('expanded');
+ });
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
</body>
diff --git a/animations/04-micro-interactions/drawer-slide/index.html b/animations/04-micro-interactions/drawer-slide/index.html
index cd2053af..33f3d898 100644
--- a/animations/04-micro-interactions/drawer-slide/index.html
+++ b/animations/04-micro-interactions/drawer-slide/index.html
@@ -41,21 +41,17 @@
.content-line{height:10px;background:rgba(255,255,255,.06);border-radius:4px}
.content-line.w100{width:100%}.content-line.w80{width:80%}.content-line.w60{width:60%}.content-line.w40{width:40%}
/* Backdrop */
- .backdrop{position:absolute;inset:0;background:rgba(0,0,0,var(--backdrop-op));opacity:0;transition:opacity var(--open-dur) var(--open-ease);pointer-events:none;z-index:5}
- .backdrop.visible{opacity:1;pointer-events:auto}
+ .backdrop{position:absolute;inset:0;background:rgba(0,0,0,var(--backdrop-op));opacity:0;transition:opacity var(--close-dur) var(--close-ease);pointer-events:none;z-index:5}
+ .backdrop.visible{opacity:1;pointer-events:auto;transition:opacity var(--open-dur) var(--open-ease)}
/* Drawer */
- .drawer{position:absolute;top:0;bottom:0;width:var(--drawer-w);background:var(--ui-bg);border-right:1px solid var(--ui-border);z-index:10;display:flex;flex-direction:column;transform:translateX(-100%);transition:transform var(--open-dur) var(--open-ease);will-change:transform;overflow:hidden}
+ .drawer{position:absolute;top:0;left:0;bottom:0;width:var(--drawer-w);background:var(--ui-bg);border-right:1px solid var(--ui-border);z-index:10;display:flex;flex-direction:column;transform:translateX(-100%);transition:transform var(--close-dur) var(--close-ease);will-change:transform;overflow:hidden;touch-action:pan-y}
.drawer.right{left:auto;right:0;border-right:none;border-left:1px solid var(--ui-border);transform:translateX(100%)}
- .drawer.top{width:auto;left:0;right:0;top:0;bottom:auto;height:200px;transform:translateY(-100%)}
- .drawer.bottom{width:auto;left:0;right:0;top:auto;bottom:0;height:200px;transform:translateY(100%)}
- .drawer.open{transform:translate(0,0);transition-duration:var(--open-dur);transition-timing-function:var(--open-ease)}
- .drawer.closing{transform:translateX(-100%);transition-duration:var(--close-dur);transition-timing-function:var(--close-ease)}
- .drawer.right.closing{transform:translateX(100%)}
- .drawer.top.closing,.drawer.bottom.closing{transform:translateY(0)}
- .drawer.top.open,.drawer.bottom.open{transform:translateY(0)}
+ .drawer.top{width:auto;left:0;right:0;top:0;bottom:auto;height:200px;transform:translateY(-100%);touch-action:pan-x}
+ .drawer.bottom{width:auto;left:0;right:0;top:auto;bottom:0;height:200px;transform:translateY(100%);touch-action:pan-x}
+ .drawer.open{transform:translate(0,0);transition:transform var(--open-dur) var(--open-ease)}
.drawer-header{display:flex;align-items:center;justify-content:space-between;padding:16px;border-bottom:1px solid var(--ui-border);flex-shrink:0}
.drawer-title{font-size:12px;font-weight:bold;text-transform:uppercase;letter-spacing:1px}
- .close-btn{background:none;border:none;color:var(--ui-muted);font-size:18px;cursor:pointer;width:36px;height:36px;display:flex;align-items:center;justify-content:center;border-radius:4px}
+ .close-btn{background:none;border:none;color:var(--ui-muted);font-size:18px;cursor:pointer;width:44px;height:44px;display:flex;align-items:center;justify-content:center;border-radius:4px}
@media(hover:hover){.close-btn:hover{color:var(--ui-text)}}
.drawer-body{padding:16px;display:flex;flex-direction:column;gap:4px;flex:1;overflow-y:auto}
.nav-item{padding:10px 12px;border-radius:6px;font-size:12px;cursor:pointer;transition:background .15s;min-height:44px;display:flex;align-items:center}
@@ -72,7 +68,7 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
.kv .v{color:var(--ui-text)}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}}
@media(prefers-reduced-motion:reduce){.drawer,.backdrop{transition:none!important}}
</style>
<style id="ah-inject">
@@ -145,14 +141,13 @@ body{padding-top:46px}
const backdrop=document.getElementById('backdrop');
const openBtn=document.getElementById('open-btn');
const stateEl=document.getElementById('state-v');
- let isOpen=false,side='left',dragStartX=0,dragStartY=0;
+ let isOpen=false,side='left',dragging=false,dragStartX=0,dragStartY=0;
function open(){
drawer.classList.add('open');backdrop.classList.add('visible');
openBtn.setAttribute('aria-expanded','true');isOpen=true;stateEl.textContent='Open';
}
function close(){
- const closeClass=side==='right'?'right closing':(side==='top'||side==='bottom')?'closing':side+' closing';
drawer.classList.remove('open');backdrop.classList.remove('visible');
openBtn.setAttribute('aria-expanded','false');isOpen=false;stateEl.textContent='Closed';
}
@@ -163,8 +158,10 @@ body{padding-top:46px}
document.addEventListener('keydown',e=>{if(e.key==='Escape'&&isOpen)close()});
// Swipe to close
- drawer.addEventListener('pointerdown',e=>{dragStartX=e.clientX;dragStartY=e.clientY});
- drawer.addEventListener('pointerup',e=>{
+ drawer.addEventListener('pointerdown',e=>{dragging=true;dragStartX=e.clientX;dragStartY=e.clientY});
+ document.addEventListener('pointercancel',()=>{dragging=false});
+ document.addEventListener('pointerup',e=>{
+ if(!dragging)return;dragging=false;
const dx=e.clientX-dragStartX,dy=e.clientY-dragStartY;
if(side==='left'&&dx<-50)close();
if(side==='right'&&dx>50)close();
@@ -175,8 +172,11 @@ body{padding-top:46px}
document.getElementById('side-sel').addEventListener('change',e=>{
if(isOpen)close();
side=e.target.value;
+ drawer.style.transition='none';
drawer.className='drawer';
if(side!=='left')drawer.classList.add(side);
+ void drawer.offsetWidth;
+ drawer.style.transition='';
});
document.getElementById('odur-sl').addEventListener('input',e=>{
document.getElementById('odur-v').textContent=e.target.value+'ms';
diff --git a/animations/04-micro-interactions/focus-ring/index.html b/animations/04-micro-interactions/focus-ring/index.html
index 92d7c107..2c26ea06 100644
--- a/animations/04-micro-interactions/focus-ring/index.html
+++ b/animations/04-micro-interactions/focus-ring/index.html
@@ -47,7 +47,7 @@
/* ring-glow */
.ring-glow .focusable:focus-visible{border-color:var(--ring-color);outline:var(--ring-w) solid var(--ring-color);outline-offset:var(--ring-offset);box-shadow:0 0 0 5px rgba(255,157,92,.18);animation:ring-in var(--ring-dur) ease-out both}
/* ring-dual */
- .ring-dual .focusable:focus-visible{outline:2px solid var(--ring-color);outline-offset:var(--ring-offset);box-shadow:0 0 0 1px var(--bg),0 0 0 calc(3px + var(--ring-offset)) var(--ring-color);animation:ring-in var(--ring-dur) ease-out both}
+ .ring-dual .focusable:focus-visible{outline:var(--ring-w) solid var(--ring-color);outline-offset:var(--ring-offset);box-shadow:0 0 0 1px var(--bg),0 0 0 calc(var(--ring-w) + 1px + var(--ring-offset)) var(--ring-color);animation:ring-in var(--ring-dur) ease-out both}
@keyframes ring-in{from{outline-offset:calc(var(--ring-offset) + 8px);opacity:.3}to{outline-offset:var(--ring-offset);opacity:1}}
.form-btn{background:var(--ui-accent);color:#000;border:none;font-family:monospace;font-size:12px;font-weight:bold;padding:0 20px;border-radius:4px;cursor:pointer;min-height:44px;width:100%;outline:none}
.form-link{color:var(--ui-accent);text-decoration:none;font-size:12px;padding:10px 2px;display:inline-block;min-height:44px;line-height:24px;outline:none}
@@ -61,9 +61,9 @@
.sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
.sv{width:40px;text-align:right;color:var(--ui-text)}
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:420px;padding:20px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:420px;padding:20px}.tab-step{padding:8px 9px;white-space:nowrap}}
/* Reduced motion: keep the focus outline (a11y) but drop the ring-in expansion */
@media(prefers-reduced-motion:reduce){.focusable,.tab-step,.form-btn,.form-link,.focusable:focus-visible,.form-btn:focus-visible,.form-link:focus-visible{animation:none!important;transition:none!important}}
</style>
diff --git a/animations/04-micro-interactions/form-field-morph/index.html b/animations/04-micro-interactions/form-field-morph/index.html
index efc1c6ba..0b502fb5 100644
--- a/animations/04-micro-interactions/form-field-morph/index.html
+++ b/animations/04-micro-interactions/form-field-morph/index.html
@@ -34,11 +34,12 @@
.form{display:flex;flex-direction:column;gap:24px;width:100%;max-width:320px}
/* Float field */
.float-field{position:relative;padding-top:20px}
- .float-field label{position:absolute;left:0;top:20px;font-size:12px;color:var(--ui-muted);transition:transform var(--field-dur) ease,font-size var(--field-dur) ease,color var(--field-dur) ease;pointer-events:none;transform-origin:left center}
+ .float-field label{position:absolute;left:0;top:20px;height:44px;display:flex;align-items:center;font-size:12px;color:var(--ui-muted);transition:transform var(--field-dur) ease,font-size var(--field-dur) ease,color var(--field-dur) ease;pointer-events:none;transform-origin:left center}
+ .float-field:has(textarea) label{top:26px;height:auto}
.float-field input,.float-field textarea{display:block;width:100%;background:transparent;border:none;border-bottom:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:13px;padding:6px 0;outline:none;transition:border-color var(--field-dur) ease;min-height:44px}
.float-field textarea{min-height:80px;resize:none}
- .float-field .underline{position:absolute;bottom:0;left:0;width:0;height:2px;background:var(--focus-color);transition:width var(--field-dur) ease}
- .float-field:focus-within .underline{width:100%}
+ .float-field .underline{position:absolute;bottom:0;left:0;width:100%;height:2px;background:var(--focus-color);transform:scaleX(0);transform-origin:left center;transition:transform var(--field-dur) ease}
+ .float-field:focus-within .underline{transform:scaleX(1)}
.float-field:focus-within label,
.float-field.filled label{transform:translateY(calc(var(--float-dist)*-1)) scale(var(--label-scale));color:var(--focus-color)}
/* Variant 2: box input */
@@ -55,10 +56,10 @@
.sr{display:flex;align-items:center;gap:6px;font-size:10px}
.sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
.sv{width:44px;text-align:right;color:var(--ui-text)}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}
.kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
.kv .v{color:var(--ui-text)}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:460px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:460px}}
@media(prefers-reduced-motion:reduce){.float-field label,.float-field input,.float-field .underline,.box-field label,.box-field input{transition:none!important}}
</style>
<style id="ah-inject">
@@ -124,7 +125,7 @@ body{padding-top:46px}
<script>
const floatFields=document.querySelectorAll('.float-field');
const boxFields=document.querySelectorAll('.box-field');
- const allInputs=document.querySelectorAll('input,textarea');
+ const allInputs=document.querySelectorAll('.form input,.form textarea');
const filledEl=document.getElementById('filled-count');
function updateFilled(){
diff --git a/animations/04-micro-interactions/hamburger-menu-toggle/index.html b/animations/04-micro-interactions/hamburger-menu-toggle/index.html
index 12756339..1cfe387a 100644
--- a/animations/04-micro-interactions/hamburger-menu-toggle/index.html
+++ b/animations/04-micro-interactions/hamburger-menu-toggle/index.html
@@ -41,9 +41,10 @@
.bar.mid{top:50%;margin-top:calc(var(--bar-h)/-2)}
.bar.bot{bottom:0;transform-origin:center}
/* Open state: top+bottom rotate to cross, middle fades */
- .burger[aria-expanded="true"] .bar.top{transform:translateY(16px) rotate(45deg)}
+ /* Travel = half the box height minus half a bar, so the arms meet at any thickness */
+ .burger[aria-expanded="true"] .bar.top{transform:translateY(calc(18px - var(--bar-h)/2)) rotate(45deg)}
.burger[aria-expanded="true"] .bar.mid{opacity:0;transform:scaleX(.2)}
- .burger[aria-expanded="true"] .bar.bot{transform:translateY(-16px) rotate(-45deg)}
+ .burger[aria-expanded="true"] .bar.bot{transform:translateY(calc(var(--bar-h)/2 - 18px)) rotate(-45deg)}
.burger[aria-expanded="true"]{border-color:var(--ui-accent)}
/* Slide-down menu */
.menu{width:100%;max-width:280px;overflow:hidden;max-height:0;opacity:0;transition:max-height var(--dur) var(--ease),opacity var(--dur) var(--ease)}
@@ -67,7 +68,7 @@
.sval{width:52px;text-align:right;color:var(--ui-text)}
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
@media(hover:hover){.burger:hover{border-color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:400px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage-wrap,aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:400px}}
@media(prefers-reduced-motion:reduce){.bar,.menu,.menu li,.burger{transition:none!important}.menu li{transition-delay:0ms!important}}
</style>
<style id="ah-inject">
diff --git a/animations/04-micro-interactions/heart-burst/index.html b/animations/04-micro-interactions/heart-burst/index.html
index 61cdc382..59b65414 100644
--- a/animations/04-micro-interactions/heart-burst/index.html
+++ b/animations/04-micro-interactions/heart-burst/index.html
@@ -49,7 +49,7 @@
.sval{width:52px;text-align:right;color:var(--ui-text)}
.kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
.kv .v{color:var(--ui-text)}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:420px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:420px}}
@media(prefers-reduced-motion:reduce){.like-btn.pop .heart{animation:none}}
</style>
<style id="ah-inject">
diff --git a/animations/04-micro-interactions/loading-spinner/index.html b/animations/04-micro-interactions/loading-spinner/index.html
index 828239d0..0e120021 100644
--- a/animations/04-micro-interactions/loading-spinner/index.html
+++ b/animations/04-micro-interactions/loading-spinner/index.html
@@ -39,13 +39,13 @@
@keyframes spin{to{transform:rotate(360deg)}}
/* 2. Dots rotating */
.sp-dots{width:var(--sz);height:var(--sz);position:relative;animation:spin var(--spd) linear infinite}
- .sp-dots span{position:absolute;width:8px;height:8px;border-radius:50%;background:var(--clr);top:50%;left:50%;transform-origin:0 0}
- .sp-dots span:nth-child(1){transform:rotate(0deg) translateX(14px);opacity:1}
- .sp-dots span:nth-child(2){transform:rotate(60deg) translateX(14px);opacity:.8}
- .sp-dots span:nth-child(3){transform:rotate(120deg) translateX(14px);opacity:.6}
- .sp-dots span:nth-child(4){transform:rotate(180deg) translateX(14px);opacity:.4}
- .sp-dots span:nth-child(5){transform:rotate(240deg) translateX(14px);opacity:.25}
- .sp-dots span:nth-child(6){transform:rotate(300deg) translateX(14px);opacity:.1}
+ .sp-dots span{position:absolute;width:calc(var(--sz)*0.2);height:calc(var(--sz)*0.2);border-radius:50%;background:var(--clr);top:50%;left:50%;transform-origin:0 0}
+ .sp-dots span:nth-child(1){transform:rotate(0deg) translateX(calc(var(--sz)*0.35));opacity:1}
+ .sp-dots span:nth-child(2){transform:rotate(60deg) translateX(calc(var(--sz)*0.35));opacity:.8}
+ .sp-dots span:nth-child(3){transform:rotate(120deg) translateX(calc(var(--sz)*0.35));opacity:.6}
+ .sp-dots span:nth-child(4){transform:rotate(180deg) translateX(calc(var(--sz)*0.35));opacity:.4}
+ .sp-dots span:nth-child(5){transform:rotate(240deg) translateX(calc(var(--sz)*0.35));opacity:.25}
+ .sp-dots span:nth-child(6){transform:rotate(300deg) translateX(calc(var(--sz)*0.35));opacity:.1}
/* 3. SVG arc */
.sp-arc{width:var(--sz);height:var(--sz);animation:spin var(--spd) linear infinite}
.sp-arc circle{fill:none;stroke:var(--clr);stroke-width:4;stroke-linecap:round;stroke-dasharray:60 100;animation:arc-pulse calc(var(--spd)*2) ease-in-out infinite}
@@ -70,9 +70,9 @@
.sr{display:flex;align-items:center;gap:6px;font-size:10px}
.sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
.sv{width:44px;text-align:right;color:var(--ui-text)}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:420px}.grid{grid-template-columns:repeat(2,1fr)}}
- @media(prefers-reduced-motion:reduce){*{animation-duration:.01ms!important}}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:420px}.grid{grid-template-columns:repeat(2,1fr)}}
+ @media(prefers-reduced-motion:reduce){[class^=sp-],[class^=sp-] *{animation-play-state:paused!important}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -153,7 +153,7 @@ body{padding-top:46px}
document.getElementById('clr-pick').addEventListener('input',e=>{
document.documentElement.style.setProperty('--clr',e.target.value);
document.querySelector('.sp-pulse').style.borderColor=e.target.value;
- document.querySelector('.sp-pulse').style.background=e.target.value.replace('#','rgba(')+',0.15)';
+ document.querySelector('.sp-pulse').style.background=e.target.value+'26';
});
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/04-micro-interactions/magnetic-button/index.html b/animations/04-micro-interactions/magnetic-button/index.html
index ef8d5341..52fd4687 100644
--- a/animations/04-micro-interactions/magnetic-button/index.html
+++ b/animations/04-micro-interactions/magnetic-button/index.html
@@ -32,8 +32,8 @@
/* Radius ring — purely visual, follows the button */
.ring{position:absolute;width:calc(var(--radius)*2px);height:calc(var(--radius)*2px);border:1px dashed rgba(255,157,92,.35);border-radius:50%;pointer-events:none;opacity:0;transition:opacity .2s}
.ring.show{opacity:1}
- .mag{position:relative;border:none;cursor:pointer;background:var(--ui-accent);color:#1a0e05;font-family:var(--disp);font-weight:700;font-size:clamp(15px,2vw,18px);letter-spacing:.01em;padding:20px 40px;min-height:56px;border-radius:40px;transition:transform .55s cubic-bezier(.22,1,.36,1);will-change:transform}
- .mag.pressed{transform:scale(.94)}
+ .mag{position:relative;border:none;cursor:pointer;background:var(--ui-accent);color:#1a0e05;font-family:var(--disp);font-weight:700;font-size:clamp(15px,2vw,18px);letter-spacing:.01em;padding:20px 40px;min-height:56px;border-radius:40px;transform:translate(var(--tx,0px),var(--ty,0px));transition:transform .55s cubic-bezier(.22,1,.36,1);will-change:transform}
+ .mag.pressed{transform:translate(var(--tx,0px),var(--ty,0px)) scale(.94)}
.mag .lbl{display:inline-block;transition:transform .55s cubic-bezier(.22,1,.36,1);will-change:transform}
.hint{position:absolute;bottom:18px;left:0;right:0;text-align:center;font-size:10px;color:var(--ui-muted);letter-spacing:.5px;pointer-events:none}
aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
@@ -47,7 +47,7 @@
.tog-inp input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
.kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
.kv .v{color:var(--ui-text)}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:420px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:420px}}
@media(prefers-reduced-motion:reduce){.mag,.mag .lbl{transition:transform .12s linear}}
</style>
<style id="ah-inject">
@@ -97,7 +97,7 @@ let strength=0.35,radius=160;
document.getElementById('mode-v').textContent=hasHover?'pointer (magnet)':'touch (press)';
function reset(){
- btn.style.transform='';lbl.style.transform='';ring.style.left='';ring.style.top='';
+ btn.style.removeProperty('--tx');btn.style.removeProperty('--ty');lbl.style.transform='';ring.style.left='';ring.style.top='';
document.getElementById('pull-v').textContent='0px';
}
@@ -113,7 +113,7 @@ if(hasHover){
// Falloff: full strength at center, easing to 0 at the radius edge
const pull=(1-dist/radius);
const tx=dx*strength*pull, ty=dy*strength*pull;
- btn.style.transform=`translate(${tx}px,${ty}px)`;
+ btn.style.setProperty('--tx',tx+'px');btn.style.setProperty('--ty',ty+'px');
lbl.style.transform=`translate(${tx*0.35}px,${ty*0.35}px)`;
document.getElementById('pull-v').textContent=Math.round(Math.hypot(tx,ty))+'px';
}else{ reset(); }
diff --git a/animations/04-micro-interactions/modal-expand/index.html b/animations/04-micro-interactions/modal-expand/index.html
index a7538f59..61a4fc26 100644
--- a/animations/04-micro-interactions/modal-expand/index.html
+++ b/animations/04-micro-interactions/modal-expand/index.html
@@ -63,7 +63,7 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}.modal-close,.modal-confirm{height:44px}}
@media(prefers-reduced-motion:reduce){.modal,.modal-backdrop{transition:none!important}.modal.open{transform:scale(1)!important;opacity:1!important}}
</style>
<style id="ah-inject">
@@ -141,22 +141,17 @@ body{padding-top:46px}
const stage=document.getElementById('stage');
const sr=stage.getBoundingClientRect();
const br=btn.getBoundingClientRect();
- const mr=modal.getBoundingClientRect();
// Button center relative to stage
const bx=br.left+br.width/2-sr.left;
const by=br.top+br.height/2-sr.top;
- // Modal center in stage
- const mx=sr.width/2;
- const my=sr.height/2-80;
- // Origin relative to modal
- const ox=bx-mx+mr.width/2;
- const oy=by-my+mr.height/2;
+ // Origin relative to the modal's laid-out top-left corner.
+ // offsetLeft/Top ignore the closed-state scale transform, unlike getBoundingClientRect.
+ const ox=bx-modal.offsetLeft;
+ const oy=by-modal.offsetTop;
modal.style.transformOrigin=`${ox.toFixed(0)}px ${oy.toFixed(0)}px`;
originLabel.textContent=`${ox.toFixed(0)}px, ${oy.toFixed(0)}px`;
- if(document.getElementById('debug-tog').checked){
- originDot.style.left=bx+'px';originDot.style.top=by+'px';
- originDot.classList.add('show');
- }
+ originDot.style.left=bx+'px';originDot.style.top=by+'px';
+ originDot.classList.toggle('show',document.getElementById('debug-tog').checked);
backdrop.classList.add('visible');modal.classList.add('open');isOpen=true;
}
function closeModal(){
@@ -184,6 +179,9 @@ body{padding-top:46px}
document.getElementById('ease-sel').addEventListener('change',e=>{
document.documentElement.style.setProperty('--modal-ease',e.target.value);
});
+ document.getElementById('debug-tog').addEventListener('change',e=>{
+ originDot.classList.toggle('show',e.target.checked&&isOpen);
+ });
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
</body>
diff --git a/animations/04-micro-interactions/progress-animation/index.html b/animations/04-micro-interactions/progress-animation/index.html
index f68a443c..37257415 100644
--- a/animations/04-micro-interactions/progress-animation/index.html
+++ b/animations/04-micro-interactions/progress-animation/index.html
@@ -23,7 +23,7 @@
@font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-800.woff2') format('woff2');font-weight:800;font-display:swap}
@font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-400.woff2') format('woff2');font-weight:400;font-display:swap}
@font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-500.woff2') format('woff2');font-weight:500;font-display:swap}
- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#ff9d5c;--ui-text:#f4f4f2;--ui-muted:#77777e;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px;--prog-dur:2000ms;--prog-color:#58a6ff;--prog-ease:ease-out}
+ :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#ff9d5c;--ui-text:#f4f4f2;--ui-muted:#77777e;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px;--prog-dur:2000ms;--prog-color:#58a6ff}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
body{background:var(--bg);color:var(--ui-text);font-family:var(--mono);-webkit-font-smoothing:antialiased;padding:clamp(12px,3vw,24px)}
header{margin-bottom:20px}
@@ -35,7 +35,7 @@
.prog-section{width:100%;max-width:320px}
.prog-label{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-muted);display:flex;justify-content:space-between;margin-bottom:8px}
.prog-track{height:8px;background:var(--ui-border);border-radius:4px;overflow:hidden}
- .prog-fill{height:100%;background:var(--prog-color);width:0%;border-radius:4px;transition:width var(--prog-dur) var(--prog-ease)}
+ .prog-fill{height:100%;background:var(--prog-color);width:0%;border-radius:4px}
.prog-fill.indet{width:40%!important;animation:indet var(--prog-dur) ease-in-out infinite;transition:none}
@keyframes indet{0%{transform:translateX(-150%)}100%{transform:translateX(350%)}}
/* Circular */
@@ -43,7 +43,7 @@
.prog-circle{position:relative;width:80px;height:80px;flex-shrink:0}
.prog-circle svg{transform:rotate(-90deg)}
.prog-ring{fill:none;stroke:var(--ui-border);stroke-width:6}
- .prog-arc{fill:none;stroke:var(--prog-color);stroke-width:6;stroke-linecap:round;stroke-dasharray:201;stroke-dashoffset:201;transition:stroke-dashoffset var(--prog-dur) var(--prog-ease)}
+ .prog-arc{fill:none;stroke:var(--prog-color);stroke-width:6;stroke-linecap:round;stroke-dasharray:201;stroke-dashoffset:201}
.prog-pct{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:bold}
/* Steps */
.steps{display:flex;gap:4px;align-items:center;width:100%;max-width:320px}
@@ -64,9 +64,9 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:500px}}
- @media(prefers-reduced-motion:reduce){.prog-fill,.prog-arc{transition:none!important}.prog-fill.indet{animation:none!important;width:100%!important}}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:500px}}
+ @media(prefers-reduced-motion:reduce){.prog-fill.indet{animation:none!important;width:100%!important}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -133,20 +133,23 @@ body{padding-top:46px}
</aside>
</div>
<script>
- let dur=2000,target=100,running=false,animRaf=null;
+ let dur=2000,target=100,running=false,animRaf=null,indetTimer=null;
const linearFill=document.getElementById('linear-fill');
const arc=document.getElementById('prog-arc');
const pctLabel=document.getElementById('pct-label');
const circPct=document.getElementById('circ-pct');
const stepEl=document.getElementById('steps');
const stepLabel=document.getElementById('step-label');
+ const indetTog=document.getElementById('indet-tog');
const steps=[...stepEl.querySelectorAll('.step')];
const CIRC=201;
+ const EASE={'ease-out':t=>1-(1-t)**3,'linear':t=>t,'ease-in-out':t=>t<.5?4*t*t*t:1-(-2*t+2)**3/2};
+ let ease=EASE['ease-out'];
+ const reduceMotion=matchMedia('(prefers-reduced-motion: reduce)');
function setProgress(p){
const pct=Math.round(p);
- const indet=document.getElementById('indet-tog').checked;
- if(!indet){linearFill.style.width=p+'%';}
+ linearFill.style.width=p+'%';
arc.style.strokeDashoffset=CIRC*(1-p/100);
pctLabel.textContent=pct+'%';
circPct.textContent=pct+'%';
@@ -155,23 +158,27 @@ body{padding-top:46px}
stepLabel.textContent=doneSteps+' / 5';
}
+ function startIndet(){
+ linearFill.classList.add('indet');
+ clearTimeout(indetTimer);
+ indetTimer=setTimeout(()=>{linearFill.classList.remove('indet');},dur*2);
+ }
+
function startAnim(){
- if(running)return;
+ if(animRaf)cancelAnimationFrame(animRaf);
setProgress(0);running=true;
+ if(indetTog.checked)startIndet();
+ if(reduceMotion.matches){setProgress(target);running=false;animRaf=null;return;}
const start=performance.now();
- const indet=document.getElementById('indet-tog').checked;
- if(indet){linearFill.classList.add('indet');setTimeout(()=>{linearFill.classList.remove('indet');running=false;},dur*2);}
function tick(now){
const t=Math.min((now-start)/dur,1);
- setProgress(target*t);
+ setProgress(target*ease(t));
if(t<1){animRaf=requestAnimationFrame(tick);}else{running=false;animRaf=null;}
}
animRaf=requestAnimationFrame(tick);
}
- document.getElementById('play-btn').addEventListener('click',()=>{
- if(animRaf)cancelAnimationFrame(animRaf);running=false;startAnim();
- });
+ document.getElementById('play-btn').addEventListener('click',startAnim);
document.getElementById('dur-sl').addEventListener('input',e=>{
dur=+e.target.value;document.getElementById('dur-v').textContent=(dur/1000).toFixed(1)+'s';
document.documentElement.style.setProperty('--prog-dur',dur+'ms');
@@ -180,14 +187,14 @@ body{padding-top:46px}
target=+e.target.value;document.getElementById('target-v').textContent=target+'%';
});
document.getElementById('ease-sel').addEventListener('change',e=>{
- document.documentElement.style.setProperty('--prog-ease',e.target.value);
+ ease=EASE[e.target.value]||EASE['ease-out'];
});
document.getElementById('color-pick').addEventListener('input',e=>{
document.documentElement.style.setProperty('--prog-color',e.target.value);
- arc.style.stroke=e.target.value;
});
- document.getElementById('indet-tog').addEventListener('change',e=>{
- if(!e.target.checked)linearFill.classList.remove('indet');
+ indetTog.addEventListener('change',e=>{
+ if(e.target.checked){if(running)startIndet();}
+ else{clearTimeout(indetTimer);linearFill.classList.remove('indet');}
});
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/04-micro-interactions/pull-to-refresh/index.html b/animations/04-micro-interactions/pull-to-refresh/index.html
index e568e204..039016d0 100644
--- a/animations/04-micro-interactions/pull-to-refresh/index.html
+++ b/animations/04-micro-interactions/pull-to-refresh/index.html
@@ -80,7 +80,7 @@
.btn:focus-visible{outline:2px solid var(--ui-accent);outline-offset:2px}
@media(hover:hover){.btn:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
.status{font-size:10px;color:var(--ui-muted);min-height:14px}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:60vh;min-height:380px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage-wrap,aside{width:100%}:root{--stage-h:auto}.stage{height:60vh;min-height:380px}}
@media(prefers-reduced-motion:reduce){.scroller,.indicator{transition:none!important}.card.fresh{animation:none}}
</style>
<style id="ah-inject">
@@ -189,6 +189,8 @@ body{padding-top:46px}
}
scroller.addEventListener('pointerup',release);
scroller.addEventListener('pointercancel',release);
+ // Once the pull is claimed, stop the browser from turning the touch into a native pan (which would fire pointercancel).
+ scroller.addEventListener('touchmove',e=>{ if(pulling)e.preventDefault(); },{passive:false});
function startRefresh(){
if(refreshing)return;
@@ -214,7 +216,7 @@ body{padding-top:46px}
$('th').addEventListener('input',e=>{ threshold=+e.target.value; $('thv').textContent=threshold+'px'; });
$('re').addEventListener('input',e=>{ resistance=+e.target.value; $('rev').textContent=(+e.target.value).toFixed(1)+'×'; });
$('du').addEventListener('input',e=>{ dur=+e.target.value; $('duv').textContent=dur+'ms'; });
- $('style').addEventListener('change',e=>{ spin.className='spin s-'+e.target.value; });
+ $('style').addEventListener('change',e=>{ spin.classList.remove('s-ring','s-dots','s-bars'); spin.classList.add('s-'+e.target.value); });
$('trigger').addEventListener('click',startRefresh); // keyboard/button fallback
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/04-micro-interactions/segmented-control/index.html b/animations/04-micro-interactions/segmented-control/index.html
index c41c8422..76435407 100644
--- a/animations/04-micro-interactions/segmented-control/index.html
+++ b/animations/04-micro-interactions/segmented-control/index.html
@@ -36,7 +36,7 @@ header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
.seg{position:relative;display:inline-flex;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:12px;padding:4px;max-width:100%;overflow:hidden}
.seg-ind{position:absolute;top:4px;left:0;height:calc(100% - 8px);border-radius:9px;background:var(--ui-accent);transform-origin:left center;transform:translateX(var(--x,0)) scaleX(var(--sx,1));width:var(--w,0);transition:transform var(--dur) var(--ease);will-change:transform;z-index:0}
.seg.underline .seg-ind{top:auto;bottom:2px;height:2px;border-radius:2px}
-.seg-opt{position:relative;z-index:1;appearance:none;background:none;border:0;cursor:pointer;font-family:var(--mono);font-size:clamp(11px,1.4vw,13px);color:var(--ui-muted);padding:0 clamp(12px,2.4vw,22px);min-height:44px;display:inline-flex;align-items:center;justify-content:center;white-space:nowrap;border-radius:9px;transition:color var(--dur) var(--ease);outline:none;-webkit-tap-highlight-color:transparent}
+.seg-opt{position:relative;z-index:1;appearance:none;background:none;border:0;cursor:pointer;font-family:var(--mono);font-size:clamp(11px,1.4vw,13px);color:var(--ui-muted);padding:0 clamp(10px,2.4vw,22px);min-width:44px;min-height:44px;display:inline-flex;align-items:center;justify-content:center;white-space:nowrap;border-radius:9px;transition:color var(--dur) var(--ease);outline:none;-webkit-tap-highlight-color:transparent}
.seg-opt[aria-checked="true"]{color:#0b0b0d;font-weight:500}
.seg.underline .seg-opt[aria-checked="true"]{color:var(--ui-accent)}
.seg-opt:focus-visible{box-shadow:0 0 0 2px var(--bg),0 0 0 4px var(--ui-accent)}
@@ -52,7 +52,7 @@ aside{width:clamp(210px,24vw,260px);flex-shrink:0;background:var(--ui-bg);border
.sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
.sval{width:52px;text-align:right;color:var(--ui-text)}
select{background:var(--bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
-@media(max-width:600px){.layout{flex-direction:column}aside{width:100%}}
+@media(max-width:600px){.layout{flex-direction:column}.stage-wrap,aside{width:100%}.stage{padding-left:12px;padding-right:12px}}
@media(prefers-reduced-motion:reduce){.seg-ind,.seg-opt{transition:none!important}}
</style>
<style id="ah-inject">
@@ -122,20 +122,20 @@ function build(n){
seg.appendChild(b);opts.push(b);
}
current=Math.min(current,n-1);
- // measure once from a neutral position, then animate future moves
- requestAnimationFrame(()=>{move(current,false);paint();});
+ // mark the selection before first style resolution (no label crossfade on rebuild), then snap the pill
+ paint();requestAnimationFrame(()=>move(current,false));
}
// Measure the target segment and translate the indicator to it.
function move(i,animate){
const g=opts[i].getBoundingClientRect(),base=opts[0].getBoundingClientRect();
- const x=opts[i].offsetLeft; // absolute offset inside the track
+ const x=g.left-base.left+opts[0].offsetLeft; // sub-pixel offset inside the track
const sx=g.width/base.width; // scaleX to match differing widths
if(!animate)ind.style.transition='none';
ind.style.width=base.width+'px'; // fixed reference width; scaleX does the rest
ind.style.setProperty('--x',x+'px');
ind.style.setProperty('--sx',sx);
- if(!animate)requestAnimationFrame(()=>ind.style.transition='');
+ if(!animate){void ind.offsetWidth;ind.style.transition='';} // flush the snap before re-enabling transitions
}
function paint(){
diff --git a/animations/04-micro-interactions/shimmer-effect/index.html b/animations/04-micro-interactions/shimmer-effect/index.html
index fbb30acb..35c682c9 100644
--- a/animations/04-micro-interactions/shimmer-effect/index.html
+++ b/animations/04-micro-interactions/shimmer-effect/index.html
@@ -60,7 +60,7 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:440px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:440px}}
@media(prefers-reduced-motion:reduce){.skel-card::after,.skel-row::after{animation:none!important;opacity:.3}}
</style>
<style id="ah-inject">
diff --git a/animations/04-micro-interactions/skeleton-loader/index.html b/animations/04-micro-interactions/skeleton-loader/index.html
index a4a9925d..1aa6fdc1 100644
--- a/animations/04-micro-interactions/skeleton-loader/index.html
+++ b/animations/04-micro-interactions/skeleton-loader/index.html
@@ -32,7 +32,8 @@
.layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
.stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:var(--bg);display:flex;align-items:center;justify-content:center;padding:24px}
/* Card */
- .card-wrap{width:100%;max-width:340px;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:10px;padding:20px;position:relative;min-height:260px}
+ .card-wrap{width:100%;max-width:340px;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:10px;padding:20px;position:relative;min-height:260px;display:grid}
+ #skel-content,.real{grid-area:1/1}
/* Skeleton blocks */
.skel{border-radius:4px;background:var(--skel-bg);animation:pulse var(--pulse-spd) ease-in-out infinite}
@keyframes pulse{0%,100%{opacity:var(--pulse-min)}50%{opacity:1}}
@@ -46,7 +47,7 @@
.skel-header{display:flex;align-items:center;gap:14px}
.skel-header-text{flex:1}
/* Real content — hidden initially */
- .real{position:absolute;inset:0;padding:20px;opacity:0;transition:opacity 400ms ease;pointer-events:none;border-radius:10px}
+ .real{opacity:0;transition:opacity 400ms ease;pointer-events:none}
.real.visible{opacity:1;pointer-events:auto}
.real-header{display:flex;align-items:center;gap:14px;margin-bottom:14px}
.avatar{width:52px;height:52px;border-radius:50%;background:linear-gradient(135deg,#1a3060,#2a5090);display:flex;align-items:center;justify-content:center;font-size:20px;flex-shrink:0}
@@ -57,7 +58,7 @@
/* Progress bar */
.load-bar-wrap{width:100%;max-width:340px;margin-top:16px}
.load-bar-track{height:2px;background:var(--ui-border);border-radius:1px;overflow:hidden}
- .load-bar-fill{height:100%;background:var(--ui-accent);width:0%;transition:width 100ms linear;border-radius:1px}
+ .load-bar-fill{height:100%;background:var(--ui-accent);transform:scaleX(0);transform-origin:left;transition:transform 100ms linear;border-radius:1px}
.load-label{font-size:10px;color:var(--ui-muted);margin-top:6px;text-align:center}
/* Panel */
aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
@@ -67,9 +68,9 @@
.sr{display:flex;align-items:center;gap:6px;font-size:10px}
.sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
.sv{width:44px;text-align:right;color:var(--ui-text)}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;min-height:44px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:400px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:400px}}
@media(prefers-reduced-motion:reduce){.skel{animation:none!important;opacity:.6}}
</style>
<style id="ah-inject">
@@ -144,12 +145,12 @@ body{padding-top:46px}
function startLoad(){
if(timer)clearTimeout(timer);if(rafId)cancelAnimationFrame(rafId);
- skelEl.style.display='';realEl.classList.remove('visible');
- fill.style.width='0%';label.textContent='Loading…';
+ skelEl.style.visibility='';realEl.classList.remove('visible');
+ fill.style.transform='scaleX(0)';label.textContent='Loading…';
const start=performance.now();
function tick(now){
const p=Math.min((now-start)/loadDur,1);
- fill.style.width=(p*100).toFixed(1)+'%';
+ fill.style.transform='scaleX('+p.toFixed(3)+')';
if(p<1){rafId=requestAnimationFrame(tick);}
else{reveal();}
}
@@ -158,7 +159,7 @@ body{padding-top:46px}
function reveal(){
label.textContent='Loaded';
- skelEl.style.display='none';
+ skelEl.style.visibility='hidden';
realEl.classList.add('visible');
}
diff --git a/animations/04-micro-interactions/star-rating/index.html b/animations/04-micro-interactions/star-rating/index.html
index 7cb1f88d..5228677b 100644
--- a/animations/04-micro-interactions/star-rating/index.html
+++ b/animations/04-micro-interactions/star-rating/index.html
@@ -33,7 +33,7 @@
.stage-wrap{flex:1;min-width:0}
.stage{border:1px solid var(--ui-border);border-radius:8px;background:var(--bg);min-height:clamp(280px,42vh,420px);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:clamp(18px,4vh,32px);padding:clamp(16px,4vw,40px)}
/* Rating control */
- .rate{display:inline-flex;gap:clamp(4px,1.5vw,12px);outline:none;touch-action:none}
+ .rate{display:inline-flex;flex-wrap:wrap;justify-content:center;max-width:100%;gap:clamp(4px,1.5vw,12px);outline:none;touch-action:none}
.rate:focus-visible{box-shadow:0 0 0 2px var(--bg),0 0 0 4px var(--ui-accent);border-radius:8px}
.star{position:relative;width:var(--star);height:var(--star);color:var(--ui-muted);cursor:pointer;transition:color var(--fill-dur) ease;-webkit-tap-highlight-color:transparent;transform-origin:center;will-change:transform}
.star svg{position:absolute;inset:0;width:100%;height:100%;display:block}
@@ -57,13 +57,14 @@
.row{display:flex;align-items:center;justify-content:space-between;font-size:10px;min-height:44px}
.row span{color:var(--ui-muted)}
.tog{position:relative;width:44px;height:26px;border-radius:13px;background:#2a2a30;border:1px solid var(--ui-border);cursor:pointer;flex-shrink:0}
+ .tog::before{content:"";position:absolute;inset:-11px 0}
.tog::after{content:"";position:absolute;top:2px;left:2px;width:20px;height:20px;border-radius:50%;background:var(--ui-text);transition:transform .18s ease}
.tog[aria-checked=true]{background:var(--ui-accent)}
.tog[aria-checked=true]::after{transform:translateX(18px)}
.kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
.kv .v{color:var(--ui-text)}
@media(hover:hover){.star:hover{color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}aside{width:100%}}
@media(prefers-reduced-motion:reduce){.star{transition:none}.star.pop{animation:none}.tog::after{transition:none}}
</style>
<style id="ah-inject">
diff --git a/animations/04-micro-interactions/success-confetti/index.html b/animations/04-micro-interactions/success-confetti/index.html
index 23fc5f14..b0534759 100644
--- a/animations/04-micro-interactions/success-confetti/index.html
+++ b/animations/04-micro-interactions/success-confetti/index.html
@@ -45,7 +45,7 @@
.sval{width:52px;text-align:right;color:var(--ui-text)}
.kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
.kv .v{color:var(--ui-text)}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:420px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage,aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:420px}}
@media(prefers-reduced-motion:reduce){.order-btn:active{transform:none}}
</style>
<style id="ah-inject">
diff --git a/animations/04-micro-interactions/swipe-to-dismiss/index.html b/animations/04-micro-interactions/swipe-to-dismiss/index.html
index 4d785d7c..6a392040 100644
--- a/animations/04-micro-interactions/swipe-to-dismiss/index.html
+++ b/animations/04-micro-interactions/swipe-to-dismiss/index.html
@@ -59,7 +59,7 @@
.div{height:1px;background:var(--ui-border)}
.reset{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){.reset:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:420px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:420px}}
@media(prefers-reduced-motion:reduce){.row,.card.settling,.card.flung{transition:none!important}}
</style>
<style id="ah-inject">
@@ -126,7 +126,8 @@ body{padding-top:46px}
let startX=0,dx=0,dragging=false,lastX=0,lastT=0,vel=0;
card.addEventListener('pointerdown',e=>{
- dragging=true;dx=0;startX=e.clientX;lastX=e.clientX;lastT=e.now||performance.now();vel=0;
+ if(row.classList.contains('collapsing'))return; // already dismissed
+ dragging=true;dx=0;startX=e.clientX;lastX=e.clientX;lastT=performance.now();vel=0;
card.classList.remove('settling','flung');
card.setPointerCapture(e.pointerId);
card.style.cursor='grabbing';
@@ -142,9 +143,10 @@ body{padding-top:46px}
});
function end(){
if(!dragging)return;dragging=false;card.style.cursor='grab';
+ if(performance.now()-lastT>100)vel=0; // finger stopped before release: no flick
const w=card.offsetWidth;
const pastDist=Math.abs(dx)>w*threshold;
- const flick=Math.abs(vel)>0.6&&Math.abs(dx)>24; // velocity commit
+ const flick=Math.abs(vel)>0.6&&Math.abs(dx)>24&&Math.sign(vel)===Math.sign(dx); // velocity commit, only when the flick points away from rest
if(pastDist||flick){dismiss(row,card,dx>=0?1:-1);}
else{spring(card,reveal);}
}
@@ -161,8 +163,7 @@ body{padding-top:46px}
function dismiss(row,card,dir){
if(reduce){ // no fly-off flourish — collapse immediately
- row.style.height='0';row.style.opacity='0';
- setTimeout(()=>row.remove(),0);checkEmpty();return;
+ row.remove();checkEmpty();return;
}
card.classList.add('flung');
card.style.transform=`translateX(${dir*card.offsetWidth*1.25}px)`;
diff --git a/animations/04-micro-interactions/theme-toggle-morph/index.html b/animations/04-micro-interactions/theme-toggle-morph/index.html
index 18c0db4c..91d41a91 100644
--- a/animations/04-micro-interactions/theme-toggle-morph/index.html
+++ b/animations/04-micro-interactions/theme-toggle-morph/index.html
@@ -68,9 +68,9 @@
.sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
.sv{width:52px;text-align:right;color:var(--ui-text)}
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}.toggle:hover{background:#17171b}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:440px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage-wrap{width:100%}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:440px}}
@media(prefers-reduced-motion:reduce){.icon line,.icon .disc,.icon .cutout,.card-inner,.toggle{transition:none!important}}
</style>
<style id="ah-inject">
diff --git a/animations/04-micro-interactions/toast-notification/index.html b/animations/04-micro-interactions/toast-notification/index.html
index c9026713..42d5be0a 100644
--- a/animations/04-micro-interactions/toast-notification/index.html
+++ b/animations/04-micro-interactions/toast-notification/index.html
@@ -39,13 +39,13 @@
.toaster.tr{top:0;right:0;align-items:flex-end}
.toaster.bl{bottom:0;left:0;flex-direction:column-reverse;align-items:flex-start}
.toaster.br{bottom:0;right:0;flex-direction:column-reverse;align-items:flex-end}
- .toast{position:relative;width:100%;overflow:hidden;border:1px solid var(--ui-border);border-left:3px solid var(--tc,var(--info));border-radius:8px;background:var(--ui-bg);padding:12px 38px 12px 12px;display:flex;gap:10px;box-shadow:0 8px 24px rgba(0,0,0,.4);cursor:grab;touch-action:pan-y;-webkit-user-select:none;user-select:none;transition:transform .34s cubic-bezier(.22,1,.36,1),opacity .34s;will-change:transform,opacity}
+ .toast{position:relative;width:100%;overflow:hidden;border:1px solid var(--ui-border);border-left:3px solid var(--tc,var(--info));border-radius:8px;background:var(--ui-bg);padding:12px 44px 12px 12px;display:flex;gap:10px;box-shadow:0 8px 24px rgba(0,0,0,.4);cursor:grab;touch-action:pan-y;-webkit-user-select:none;user-select:none;transition:transform .34s cubic-bezier(.22,1,.36,1),opacity .34s;will-change:transform,opacity}
.toast.ok{--tc:var(--ok)} .toast.err{--tc:var(--err)} .toast.info{--tc:var(--info)}
.toast .ic{flex-shrink:0;width:22px;height:22px;border-radius:50%;background:var(--tc);color:#0b0b0d;font-family:var(--disp);font-weight:800;font-size:13px;display:flex;align-items:center;justify-content:center;line-height:1}
.toast .body{min-width:0}
.toast .ti{font-family:var(--disp);font-weight:700;font-size:12px;letter-spacing:-.01em}
.toast .ms{font-size:10.5px;color:var(--ui-muted);margin-top:2px;line-height:1.4}
- .toast .x{position:absolute;top:6px;right:6px;width:26px;height:26px;border:0;background:transparent;color:var(--ui-muted);font-size:15px;cursor:pointer;border-radius:6px;line-height:1}
+ .toast .x{position:absolute;top:50%;right:0;transform:translateY(-50%);width:44px;height:44px;border:0;background:transparent;color:var(--ui-muted);font-size:15px;cursor:pointer;border-radius:6px;line-height:1}
@media(hover:hover){.toast .x:hover{color:var(--ui-text);background:rgba(255,255,255,.06)}}
.toast .prog{position:absolute;left:0;bottom:0;height:2px;width:100%;background:var(--tc);transform-origin:left;transform:scaleX(1);animation:ah_prog var(--dur,4s) linear forwards}
@media(hover:hover){.toast:hover .prog{animation-play-state:paused}}
@@ -64,7 +64,7 @@
.clear{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:12px 8px;border-radius:6px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){.trigger:hover{filter:brightness(1.08)}.clear:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
.div{height:1px;background:var(--ui-border)}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage-wrap,aside{width:100%}}
@media(prefers-reduced-motion:reduce){.toast{transition:none!important}.toast .prog{animation:none!important;transform:scaleX(0)}}
</style>
<style id="ah-inject">
@@ -157,6 +157,7 @@ body{padding-top:46px}
const o=prev.get(t); if(o==null)return;
const d=o-t.getBoundingClientRect().top; if(!d)return;
t.style.transition='none'; t.style.transform=`translateY(${d}px)`;
+ void t.offsetWidth; // commit the inverted position before releasing it
requestAnimationFrame(()=>{t.style.transition='';t.style.transform='';});
});
}
@@ -174,7 +175,7 @@ body{padding-top:46px}
const top=corner.startsWith('t');
top?toaster.appendChild(el):toaster.insertBefore(el,toaster.firstChild);
toasts.push(el); wire(el,type);
- if(!reduce)requestAnimationFrame(()=>{el.style.opacity='1';el.style.transform='none';});
+ if(!reduce){void el.offsetWidth;requestAnimationFrame(()=>{if(el._gone)return;el.style.opacity='1';el.style.transform='none';});}
else{el.style.opacity='1';el.style.transform='none';}
if(reduce)el._to=setTimeout(()=>dismiss(el),dur*1000);
enforce(); hint.style.display='none';
@@ -201,8 +202,8 @@ body{padding-top:46px}
let x0=0,dx=0,drag=false;
el.addEventListener('pointerdown',e=>{if(e.target.closest('.x'))return;drag=true;dx=0;x0=e.clientX;el.classList.add('paused');el.style.transition='none';el.setPointerCapture(e.pointerId);});
el.addEventListener('pointermove',e=>{if(!drag)return;dx=e.clientX-x0;el.style.transform=`translateX(${dx}px)`;el.style.opacity=String(Math.max(.3,1-Math.abs(dx)/(el.offsetWidth*.8)));});
- function up(){if(!drag)return;drag=false;el.classList.remove('paused');
- if(Math.abs(dx)>el.offsetWidth*.35||Math.abs(dx)<6){dismiss(el,dx<0?-1:1);}
+ function up(e){if(!drag)return;drag=false;el.classList.remove('paused');
+ if(e.type!=='pointercancel'&&(Math.abs(dx)>el.offsetWidth*.35||Math.abs(dx)<6)){dismiss(el,dx<0?-1:1);}
else{el.style.transition='transform .3s cubic-bezier(.22,1,.36,1),opacity .3s';el.style.transform='none';el.style.opacity='1';}}
el.addEventListener('pointerup',up); el.addEventListener('pointercancel',up);
}
diff --git a/animations/04-micro-interactions/toggle-switch/index.html b/animations/04-micro-interactions/toggle-switch/index.html
index 2b8cb076..5dbcda68 100644
--- a/animations/04-micro-interactions/toggle-switch/index.html
+++ b/animations/04-micro-interactions/toggle-switch/index.html
@@ -36,17 +36,19 @@
.tog-label{flex:1;font-size:12px;color:var(--ui-text)}
.tog-sub{font-size:10px;color:var(--ui-muted);display:block;margin-top:2px}
/* Base track */
- .sw{position:relative;width:52px;height:30px;flex-shrink:0;cursor:pointer;-webkit-user-select:none;user-select:none;touch-action:manipulation}
+ /* Label is 44px tall for touch; the visible track is inset to 30px (36px for -lg) */
+ .sw{position:relative;width:52px;height:44px;flex-shrink:0;cursor:pointer;-webkit-user-select:none;user-select:none;touch-action:manipulation}
.sw input{position:absolute;opacity:0;width:0;height:0}
- .sw-track{position:absolute;inset:0;border-radius:15px;background:var(--ui-border);transition:background var(--tog-dur) var(--tog-ease)}
- .sw-thumb{position:absolute;top:3px;left:3px;width:24px;height:24px;border-radius:50%;background:#fff;transition:transform var(--tog-dur) var(--tog-ease),box-shadow var(--tog-dur) var(--tog-ease);box-shadow:0 1px 4px rgba(0,0,0,.4)}
+ .sw-track{position:absolute;inset:7px 0;border-radius:15px;background:var(--ui-border);transition:background var(--tog-dur) var(--tog-ease)}
+ .sw-thumb{position:absolute;top:10px;left:3px;width:24px;height:24px;border-radius:50%;background:#fff;transition:transform var(--tog-dur) var(--tog-ease),box-shadow var(--tog-dur) var(--tog-ease);box-shadow:0 1px 4px rgba(0,0,0,.4)}
.sw input:checked~.sw-track{background:var(--on-color)}
.sw input:checked~.sw-thumb{transform:translateX(22px)}
/* Elastic variant */
.sw.elastic .sw-thumb{transition:transform var(--tog-dur) cubic-bezier(.34,1.56,.64,1),background var(--tog-dur) var(--tog-ease)}
/* Large with icons */
- .sw-lg{width:68px;height:36px}
- .sw-lg .sw-thumb{width:30px;height:30px;display:flex;align-items:center;justify-content:center;font-size:14px;color:var(--ui-muted)}
+ .sw-lg{width:68px}
+ .sw-lg .sw-track{inset:4px 0}
+ .sw-lg .sw-thumb{top:7px;width:30px;height:30px;display:flex;align-items:center;justify-content:center;font-size:14px;color:var(--ui-muted)}
.sw-lg .sw-thumb::before{content:'🌙'}
.sw-lg input:checked~.sw-thumb{transform:translateX(32px)}
.sw-lg input:checked~.sw-thumb::before{content:'☀️'}
@@ -64,8 +66,8 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.tog-inp{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog-inp input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:420px}}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:420px}}
@media(prefers-reduced-motion:reduce){.sw-track,.sw-thumb{transition:background .1s!important}}
</style>
<style id="ah-inject">
diff --git a/animations/04-micro-interactions/tooltip-reveal/index.html b/animations/04-micro-interactions/tooltip-reveal/index.html
index 75daaa0c..6c232585 100644
--- a/animations/04-micro-interactions/tooltip-reveal/index.html
+++ b/animations/04-micro-interactions/tooltip-reveal/index.html
@@ -33,7 +33,7 @@
.stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:var(--bg);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:28px;padding:32px}
/* Tooltip base */
.tip-wrap{position:relative;display:inline-flex}
- .tooltip{position:absolute;background:var(--tip-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-size:11px;padding:7px 10px;border-radius:6px;white-space:nowrap;pointer-events:none;opacity:0;transform:scale(.95);transition:opacity var(--tip-dur) ease,transform var(--tip-dur) ease;z-index:10;max-width:200px;white-space:normal;line-height:1.5}
+ .tooltip{position:absolute;background:var(--tip-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-size:11px;padding:7px 10px;border-radius:6px;white-space:nowrap;pointer-events:none;opacity:0;transform:scale(.95);transition:opacity var(--tip-dur) ease,transform var(--tip-dur) ease;z-index:10;width:max-content;max-width:200px;white-space:normal;line-height:1.5}
.tooltip.visible{opacity:1;transform:scale(1)}
/* Positions */
.tip-top{bottom:calc(100% + 8px);left:50%;transform:translateX(-50%) scale(.95);transform-origin:bottom center}
@@ -69,8 +69,14 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:480px}}
- @media(prefers-reduced-motion:reduce){.tooltip{transition:opacity var(--tip-dur) ease!important;transform:none!important}}
+ @media(max-width:600px){
+ .layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:480px}.trunc-text{min-height:44px;line-height:24px}
+ /* No room to the right of the input on phones: flip the side tooltip below it */
+ .tip-right{left:50%;right:auto;top:calc(100% + 8px);transform:translateX(-50%) scale(.95);transform-origin:top center}
+ .tip-right.visible{transform:translateX(-50%) scale(1)}
+ .has-arrow .tip-right::after{left:50%;top:-10px;transform:translateX(-50%);border-right-color:transparent;border-bottom-color:var(--tip-bg)}
+ }
+ @media(prefers-reduced-motion:reduce){.tooltip{transition:opacity var(--tip-dur) ease!important}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -136,7 +142,7 @@ body{padding-top:46px}
let showTimer=null,hideTimer=null;
function show(){
- clearTimeout(hideTimer);
+ clearTimeout(hideTimer);clearTimeout(showTimer);
showTimer=setTimeout(()=>{tip.classList.add('visible');total++;document.getElementById('total').textContent=total;},showDelay);
}
function hide(){
diff --git a/animations/05-text-typography/enter-exit-typography/index.html b/animations/05-text-typography/enter-exit-typography/index.html
index bf6224a3..3a88ffa5 100644
--- a/animations/05-text-typography/enter-exit-typography/index.html
+++ b/animations/05-text-typography/enter-exit-typography/index.html
@@ -75,7 +75,7 @@
.sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
.sv{width:44px;text-align:right;color:var(--ui-text)}
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
@@ -133,7 +133,7 @@ const PHRASES=[
{text:'Then motion.',enter:'enter-scale',exit:'exit-scale'},
{text:'Then meaning.',enter:'enter-clip',exit:'exit-clip'},
];
-let idx=0,timer=null;
+let idx=0,timer=null,run=0;
const phraseEl=document.getElementById('phrase-el');
const phraseText=document.getElementById('phrase-text');
const dotsEl=document.getElementById('prog-dots');
@@ -155,13 +155,14 @@ const exitClasses=['exit-slide-up','exit-slide-left','exit-scale','exit-blur','e
const allPhaseClasses=[...enterClasses,...exitClasses,'state-hidden'];
function show(i,done){
- const p=PHRASES[i];
+ const p=PHRASES[i],r=run;
phraseText.textContent=p.text;
phraseEl.classList.remove(...allPhaseClasses);
phraseEl.classList.add('state-hidden');
phraseKv.textContent=(i+1)+' / '+PHRASES.length;
activeDot(i);
requestAnimationFrame(()=>requestAnimationFrame(()=>{
+ if(r!==run)return;
phaseKv.textContent='Enter';
phraseEl.classList.remove('state-hidden');
phraseEl.classList.add(p.enter);
@@ -188,10 +189,11 @@ function cycle(){
}
function start(){
- if(timer)clearTimeout(timer);
+ if(timer)clearTimeout(timer);run++;
idx=0;buildDots();
+ phraseEl.classList.remove(...allPhaseClasses);
phraseEl.classList.add('state-hidden');
- setTimeout(cycle,200);
+ timer=setTimeout(cycle,200);
}
document.getElementById('replay-btn').addEventListener('click',start);
diff --git a/animations/05-text-typography/glitch-text/index.html b/animations/05-text-typography/glitch-text/index.html
index c60d6920..ec831aec 100644
--- a/animations/05-text-typography/glitch-text/index.html
+++ b/animations/05-text-typography/glitch-text/index.html
@@ -36,8 +36,8 @@
/* Glitch text: three stacked copies via ::before/::after clones */
.glitch{
position:relative;font-family:var(--disp);font-weight:800;
- font-size:clamp(44px,12vw,120px);line-height:1;letter-spacing:-.02em;color:#fff;
- text-transform:uppercase;-webkit-user-select:none;user-select:none;
+ font-size:clamp(28px,min(12vw,120vw/var(--n,6)),120px);line-height:1;letter-spacing:-.02em;color:#fff;
+ text-transform:uppercase;white-space:nowrap;-webkit-user-select:none;user-select:none;
}
.glitch::before,.glitch::after{
content:attr(data-text);position:absolute;inset:0;
@@ -61,6 +61,9 @@
/* hover-trigger mode: layers hold still until pointer enters */
.paused .glitch::before,.paused .glitch::after{animation-play-state:paused}
@media(hover:hover){.paused:hover .glitch::before,.paused:hover .glitch::after{animation-play-state:running}}
+ .paused.active .glitch::before,.paused.active .glitch::after{animation-play-state:running}
+ /* toggling this class restarts the pseudo-element animations (reshuffles phase) */
+ .glitch.reset::before,.glitch.reset::after{animation:none}
aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
.note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
.lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
@@ -72,7 +75,7 @@
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
.div{height:1px;background:var(--ui-border)}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:360px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:360px}}
@media(prefers-reduced-motion:reduce){
.glitch::before,.glitch::after{animation:none!important;clip-path:none!important}
}
@@ -108,7 +111,7 @@ body{padding-top:46px}
<div class="lbl">RGB offset</div>
<div class="sr"><input type="range" id="off-sl" min="0" max="12" value="4" step="1"><span class="sv" id="off-sv">4px</span></div>
<div class="lbl">Speed</div>
- <div class="sr"><input type="range" id="spd-sl" min="1" max="12" value="6" step="1"><span class="sv" id="spd-sv">2.4s</span></div>
+ <div class="sr"><input type="range" id="spd-sl" min="1" max="12" value="8" step="1"><span class="sv" id="spd-sv">2.4s</span></div>
<div class="lbl">Intensity</div>
<div class="sr"><input type="range" id="int-sl" min="0" max="100" value="60" step="5"><span class="sv" id="int-sv">60%</span></div>
<div class="div"></div>
@@ -129,20 +132,34 @@ function reslice(){
// amplitude of the tear scales with intensity: low intensity = thin, rare bands
const spread=Math.round(intensity*40);
const jitter=(intensity*6).toFixed(1);
- glitch.style.setProperty('--offset',(parseInt(root.style.getPropertyValue('--offset'))||4)+'px');
- // nudge the whole element sideways for a frame to sell the tear
- glitch.style.transform=`translateX(${(Math.random()*2-1)*jitter}px)`;
- // occasionally hard-cut a fresh clip band on the ::before via inline var not possible;
- // instead we retrigger animation to reshuffle phase
- if(Math.random()<intensity){
- glitch.style.animation='none';void glitch.offsetWidth;glitch.style.animation='';
+ // in hover-trigger mode the jitter only runs while the stage is hovered / tapped active
+ const live=!stage.classList.contains('paused')||stage.matches(':hover')||stage.classList.contains('active');
+ if(live){
+ // nudge the whole element sideways for a frame to sell the tear
+ glitch.style.transform=`translateX(${(Math.random()*2-1)*jitter}px)`;
+ // occasionally restart the clone animations to reshuffle their phase
+ if(Math.random()<intensity){
+ glitch.classList.add('reset');void glitch.offsetWidth;glitch.classList.remove('reset');
+ }
+ }else{
+ glitch.style.transform='';
}
jitterTimer=setTimeout(reslice,120+rand(spread*8+60));
}
+// The CSS formula is viewport-based; measure against the real stage width and shrink further if needed.
+function fit(){
+ glitch.style.fontSize='';
+ const avail=stage.clientWidth-48,w=glitch.scrollWidth;
+ if(w>avail)glitch.style.fontSize=Math.max(16,parseFloat(getComputedStyle(glitch).fontSize)*avail/w)+'px';
+}
document.getElementById('text-inp').addEventListener('input',e=>{
const t=(e.target.value||'GLITCH');glitch.textContent=t;glitch.dataset.text=t;
+ glitch.style.setProperty('--n',t.length); // longer words shrink so they stay inside the stage
+ fit();
});
+addEventListener('resize',fit);
+fit();
document.getElementById('off-sl').addEventListener('input',e=>{
root.style.setProperty('--offset',e.target.value+'px');
document.getElementById('off-sv').textContent=e.target.value+'px';
@@ -159,6 +176,11 @@ document.getElementById('int-sl').addEventListener('input',e=>{
});
document.getElementById('hover-ck').addEventListener('change',e=>{
stage.classList.toggle('paused',e.target.checked);
+ stage.classList.remove('active');
+});
+// touch has no hover: a tap on the stage toggles the hover-trigger state instead
+stage.addEventListener('pointerdown',e=>{
+ if(e.pointerType!=='mouse'&&stage.classList.contains('paused'))stage.classList.toggle('active');
});
if(!reduce)reslice();
</script>
diff --git a/animations/05-text-typography/kinetic-typography/index.html b/animations/05-text-typography/kinetic-typography/index.html
index 2097ecb5..ae4263d6 100644
--- a/animations/05-text-typography/kinetic-typography/index.html
+++ b/animations/05-text-typography/kinetic-typography/index.html
@@ -106,7 +106,7 @@ body{padding-top:46px}
<aside>
<p class="note">Kinetic typography is choreography for words. Each transform should reinforce the meaning — a soft word dissolves; a hard word snaps in.</p>
<div class="lbl">Playback Speed</div>
- <div class="sr"><input type="range" id="spd-sl" min="5" max="20" value="10" step="1"><span class="sv" id="spd-v">1×</span></div>
+ <div class="sr"><input type="range" id="spd-sl" min="5" max="20" value="10" step="1"><span class="sv" id="spd-v">1.0×</span></div>
<div class="div"></div>
<div class="kv"><span>Phrase</span><span class="v" id="phrase-kv">1 / 6</span></div>
<div class="kv"><span>State</span><span class="v" id="state-kv">Playing</span></div>
@@ -142,8 +142,7 @@ function showPhrase(i){
if(p.sub){const s=document.createElement('span');s.className='kw sub';s.textContent=p.sub;phraseEl.appendChild(s);}
counterEl.textContent=(i+1)+' / '+PHRASES.length;
phraseKv.textContent=(i+1)+' / '+PHRASES.length;
- const pct=((i+1)/PHRASES.length*100).toFixed(0)+'%';
- if(document.getElementById('beat-tog').checked)beatFill.style.width=pct;
+ beatFill.style.width=((i+1)/PHRASES.length*100).toFixed(0)+'%';
requestAnimationFrame(()=>{
w.classList.add(p.enter);
if(p.sub)phraseEl.querySelectorAll('.sub').forEach(s=>{s.style.animationDelay='200ms';s.classList.add(p.enter);});
@@ -153,48 +152,35 @@ function showPhrase(i){
function exitPhrase(i,done){
const p=PHRASES[i];
phraseEl.querySelectorAll('.kw').forEach(w=>{
- w.classList.remove(p.enter);w.classList.add(p.exit);
+ w.style.animationDelay='';w.classList.remove(p.enter);w.classList.add(p.exit);
});
- setTimeout(done,ms(450));
+ // Every pending timeout in the chain is stored in `timer` so Play/Restart can cancel it.
+ timer=setTimeout(done,ms(450));
}
function run(){
if(running)return;running=true;stateKv.textContent='Playing';
idx=0;
function step(){
- showPhrase(idx);
- timer=setTimeout(()=>{
- exitPhrase(idx,()=>{
- idx++;
- if(idx<PHRASES.length){setTimeout(step,ms(120));}
- else{
- running=false;stateKv.textContent='Done';
- if(document.getElementById('loop-tog').checked){beatFill.style.width='0%';setTimeout(run,ms(800));}
- }
- });
- },ms(500)+ms(p.hold));
- }
- function p_hold(){return PHRASES[idx];}
- function step2(){
showPhrase(idx);
const hold=PHRASES[idx].hold;
timer=setTimeout(()=>{
exitPhrase(idx,()=>{
idx++;
- if(idx<PHRASES.length){setTimeout(step2,ms(120));}
+ if(idx<PHRASES.length){timer=setTimeout(step,ms(120));}
else{
running=false;stateKv.textContent='Done';
- if(document.getElementById('loop-tog').checked){beatFill.style.width='0%';setTimeout(run,ms(800));}
+ if(document.getElementById('loop-tog').checked){beatFill.style.width='0%';timer=setTimeout(run,ms(800));}
}
});
},ms(500+hold));
}
- step2();
+ step();
}
document.getElementById('play-btn').addEventListener('click',()=>{
- if(timer)clearTimeout(timer);running=false;beatFill.style.width='0%';
- setTimeout(run,50);
+ clearTimeout(timer);running=false;beatFill.style.width='0%';
+ timer=setTimeout(run,50);
});
document.getElementById('spd-sl').addEventListener('input',e=>{
speed=e.target.value/10;
diff --git a/animations/05-text-typography/marquee-ticker/index.html b/animations/05-text-typography/marquee-ticker/index.html
index acb552e5..baee21c3 100644
--- a/animations/05-text-typography/marquee-ticker/index.html
+++ b/animations/05-text-typography/marquee-ticker/index.html
@@ -37,15 +37,16 @@
.marq-row.accent{background:rgba(255,111,139,.05)}
.marq-track{display:flex;width:max-content;white-space:nowrap;animation:marqL linear infinite}
.marq-track.rev{animation-name:marqR}
- .marq-row:hover .marq-track{animation-play-state:paused}
+ @media(hover:hover){.marq-row:hover .marq-track{animation-play-state:paused}.marq-row:hover .pause-hint{opacity:1}}
+ .marq-row.paused .marq-track{animation-play-state:paused}
+ .marq-row.paused .pause-hint{opacity:1}
@keyframes marqL{from{transform:translateX(0)}to{transform:translateX(-50%)}}
@keyframes marqR{from{transform:translateX(-50%)}to{transform:translateX(0)}}
.marq-item{font-family:Georgia,'Times New Roman',serif;font-size:var(--marq-size);font-style:italic;line-height:1;color:#fff;padding:0 var(--marq-gap);display:flex;align-items:center;gap:var(--marq-gap)}
.marq-item.rev-row{color:rgba(255,255,255,.6)}
.sep{color:var(--ui-accent);font-style:normal;font-size:.6em;opacity:.7}
/* Pause indicator */
- .pause-hint{position:absolute;right:12px;top:50%;transform:translateY(-50%);font-size:9px;letter-spacing:1px;color:var(--ui-muted);opacity:0;transition:opacity .2s;pointer-events:none;background:var(--ui-bg);padding:3px 8px;border-radius:3px}
- .marq-row:hover .pause-hint{opacity:1}
+ .pause-hint{position:absolute;z-index:1;right:12px;top:50%;transform:translateY(-50%);font-size:9px;letter-spacing:1px;color:var(--ui-muted);opacity:0;transition:opacity .2s;pointer-events:none;background:var(--ui-bg);padding:3px 8px;border-radius:3px}
/* Panel */
aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
.note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
@@ -57,7 +58,7 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
input[type=text]{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:11px;padding:8px 10px;border-radius:4px;width:100%;min-height:44px;outline:none}
input[type=text]:focus{border-color:var(--ui-accent)}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
@media(max-width:600px){.layout{flex-direction:column;align-items:stretch}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:380px}}
@media(prefers-reduced-motion:reduce){.marq-track{animation-play-state:paused!important}}
@@ -110,18 +111,29 @@ body{padding-top:46px}
<script>
const stage=document.getElementById('stage');
+ const noHover=matchMedia('(hover:none)');
+
+ function makeItem(text,sep,reverse){
+ const item=document.createElement('div');item.className='marq-item'+(reverse?' rev-row':'');
+ item.textContent=text;
+ const s=document.createElement('span');s.className='sep';s.setAttribute('aria-hidden','true');s.textContent=sep;
+ item.appendChild(s);
+ return item;
+ }
+
function buildRow(text,sep,reverse,className){
const row=document.createElement('div');row.className='marq-row'+(className?' '+className:'');
const hint=document.createElement('div');hint.className='pause-hint';hint.textContent='PAUSED';row.appendChild(hint);
- const track=document.createElement('div');track.className='marq-track'+(reverse?' rev':'');
- // Duplicate 4× for seamless loop
- for(let i=0;i<4;i++){
- const item=document.createElement('div');item.className='marq-item'+(reverse?' rev-row':'');
- item.innerHTML=text+'<span class="sep" aria-hidden="true">'+sep+'</span>';
- track.appendChild(item);
- }
+ const track=document.createElement('div');track.className='marq-track'+(reverse?' rev':'');track.setAttribute('aria-live','off');
row.appendChild(track);
+ stage.appendChild(row);
+ // One copy must be wider than the row, so repeat the item until it is, then duplicate that copy once
+ const probe=makeItem(text,sep,reverse);track.appendChild(probe);
+ const reps=Math.max(2,Math.ceil(row.clientWidth/Math.max(probe.offsetWidth,1))+1);
+ for(let i=1;i<reps*2;i++)track.appendChild(makeItem(text,sep,reverse));
updateSpeed(track);
+ // Tap toggles pause where there is no hover
+ row.addEventListener('click',()=>{if(noHover.matches)row.classList.toggle('paused')});
return row;
}
@@ -132,19 +144,16 @@ body{padding-top:46px}
function updateSpeed(track){
const spd=+document.getElementById('spd-sl').value;
- // Estimate total track width: approximate by counting chars
- const text=getContent();
- const approxW=(text.length*40+100)*2; // 2 copies = -50% travel distance
- const dur=Math.max(approxW/spd,2);
- track.style.animationDuration=dur.toFixed(1)+'s';
+ const oneCopy=track.scrollWidth/2; // -50% travel distance
+ track.style.animationDuration=(oneCopy/spd).toFixed(2)+'s';
}
function rebuild(){
const text=getContent();const sep=getSep();
stage.innerHTML='';
- stage.appendChild(buildRow(text,sep,false,''));
- stage.appendChild(buildRow(text,sep,true,'accent'));
- stage.appendChild(buildRow(text+' · '+text,sep,false,''));
+ buildRow(text,sep,false,'');
+ buildRow(text,sep,true,'accent');
+ buildRow(text+' '+sep+' '+text,sep,false,'');
}
function refreshSpeeds(){
@@ -157,14 +166,22 @@ body{padding-top:46px}
});
document.getElementById('size-sl').addEventListener('input',e=>{
document.getElementById('size-v').textContent=e.target.value+'px';
- document.documentElement.style.setProperty('--marq-size',e.target.value+'px');
+ document.documentElement.style.setProperty('--marq-size',e.target.value+'px');refreshSpeeds();
});
document.getElementById('gap-sl').addEventListener('input',e=>{
document.getElementById('gap-v').textContent=e.target.value+'px';
- document.documentElement.style.setProperty('--marq-gap',e.target.value+'px');
+ document.documentElement.style.setProperty('--marq-gap',e.target.value+'px');refreshSpeeds();
});
+ // Width changes alter how many repeats a row needs: rebuild once the slider settles
+ document.getElementById('size-sl').addEventListener('change',rebuild);
+ document.getElementById('gap-sl').addEventListener('change',rebuild);
document.getElementById('apply-btn').addEventListener('click',rebuild);
document.getElementById('sep-sel').addEventListener('change',rebuild);
+ let resizeTimer,lastW=innerWidth;
+ addEventListener('resize',()=>{
+ if(innerWidth===lastW)return; // ignore mobile address-bar height changes
+ lastW=innerWidth;clearTimeout(resizeTimer);resizeTimer=setTimeout(rebuild,150);
+ });
rebuild();
</script>
diff --git a/animations/05-text-typography/outline-to-fill/index.html b/animations/05-text-typography/outline-to-fill/index.html
index a0acab68..4f6aac23 100644
--- a/animations/05-text-typography/outline-to-fill/index.html
+++ b/animations/05-text-typography/outline-to-fill/index.html
@@ -23,14 +23,14 @@
@font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-800.woff2') format('woff2');font-weight:800;font-display:swap}
@font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-400.woff2') format('woff2');font-weight:400;font-display:swap}
@font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-500.woff2') format('woff2');font-weight:500;font-display:swap}
- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#ff6f8b;--ui-text:#f4f4f2;--ui-muted:#77777e;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px;--fill-dur:900ms;--fill-ease:ease-in-out;--stroke-color:#ff6f8b;--fill-color:#ff6f8b;--stroke-w:2;--fill-dir:up}
+ :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#ff6f8b;--ui-text:#f4f4f2;--ui-muted:#77777e;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px;--fill-dur:900ms;--fill-ease:ease-in-out;--stroke-color:#ff6f8b;--fill-color:#ff6f8b;--stroke-w:2px;--fill-dir:up}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
body{background:var(--bg);color:var(--ui-text);font-family:var(--mono);-webkit-font-smoothing:antialiased;padding:clamp(12px,3vw,24px)}
header{margin-bottom:20px}
header h1{font-family:var(--disp);font-weight:700;font-size:clamp(11px,1.8vw,15px);letter-spacing:-.01em}
header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
.layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:#04060c;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:40px;padding:32px}
+ .stage{flex:1;min-width:0;overflow:hidden;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:#04060c;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:40px;padding:32px}
/* Shared text style */
.otf-text{
font-family:Georgia,'Times New Roman',serif;
@@ -43,13 +43,13 @@
/* Variant A: bottom-up fill via stacked layers */
.otf-wrap{position:relative;display:inline-block}
.outline-layer{
- -webkit-text-stroke:var(--stroke-w)px var(--stroke-color);
+ -webkit-text-stroke:var(--stroke-w) var(--stroke-color);
color:transparent;
position:relative;z-index:2
}
.fill-layer{
position:absolute;inset:0;
- -webkit-text-stroke:var(--stroke-w)px var(--stroke-color);
+ -webkit-text-stroke:var(--stroke-w) var(--stroke-color);
color:var(--fill-color);
clip-path:inset(100% 0 0 0);
transition:clip-path var(--fill-dur) var(--fill-ease);
@@ -63,7 +63,7 @@
/* Variant B: stroke fade, fill fade */
.stroke-fade-wrap{position:relative;display:inline-block}
.stroke-only{
- -webkit-text-stroke:var(--stroke-w)px var(--stroke-color);
+ -webkit-text-stroke:var(--stroke-w) var(--stroke-color);
color:transparent;
transition:opacity var(--fill-dur) var(--fill-ease)
}
@@ -89,12 +89,12 @@
input[type=text]{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:11px;padding:8px 10px;border-radius:4px;width:100%;min-height:44px;outline:none}
input[type=text]:focus{border-color:var(--ui-accent)}
.color-row{display:flex;gap:8px;align-items:center;font-size:10px;color:var(--ui-muted);flex-wrap:wrap}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0;flex-shrink:0}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0;flex-shrink:0}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:440px}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:440px}}
@media(prefers-reduced-motion:reduce){.fill-layer,.stroke-only,.fill-only{transition:none!important}.fill-layer{clip-path:inset(0%)!important}.stroke-fade-wrap.filled .fill-only{opacity:1!important}.stroke-fade-wrap.filled .stroke-only{opacity:0!important}}
</style>
<style id="ah-inject">
@@ -177,6 +177,17 @@ body{padding-top:46px}
['outline-layer','fill-layer','stroke-only','fill-only'].forEach(id=>{
document.getElementById(id).textContent=t;
});
+ fitText();
+ }
+
+ function fitText(){
+ // Scale long words down so they never get clipped by the stage on narrow screens
+ const avail=document.querySelector('.stage').clientWidth-64;
+ document.querySelectorAll('.otf-wrap,.stroke-fade-wrap').forEach(w=>{
+ w.style.transform='';
+ const s=avail>0?Math.min(1,avail/w.offsetWidth):1;
+ if(s<1)w.style.transform='scale('+s.toFixed(3)+')';
+ });
}
function applyDir(){
@@ -186,21 +197,26 @@ body{padding-top:46px}
}
function reset(){
+ // Snap back without a reverse transition, so the next fill runs at full length
+ const layers=[fillLayer,...strokeWrap.children];
+ layers.forEach(el=>el.style.transition='none');
fillLayer.classList.remove('filled');
strokeWrap.classList.remove('filled');
+ applyDir();
+ void fillLayer.offsetWidth;
+ layers.forEach(el=>el.style.transition='');
}
function play(){
clearTimeout(loopTimer);
reset();
- applyDir();
const dur=+document.getElementById('dur-sl').value;
requestAnimationFrame(()=>requestAnimationFrame(()=>{
fillLayer.classList.add('filled');
strokeWrap.classList.add('filled');
}));
if(document.getElementById('loop-tog').checked){
- loopTimer=setTimeout(()=>{reset();setTimeout(play,300);},dur+1400);
+ loopTimer=setTimeout(()=>{reset();loopTimer=setTimeout(play,300);},dur+1400);
}
}
@@ -211,7 +227,7 @@ body{padding-top:46px}
});
document.getElementById('sw-sl').addEventListener('input',e=>{
document.getElementById('sw-v').textContent=e.target.value+'px';
- document.documentElement.style.setProperty('--stroke-w',e.target.value);
+ document.documentElement.style.setProperty('--stroke-w',e.target.value+'px');
});
document.getElementById('stroke-pick').addEventListener('input',e=>{
document.documentElement.style.setProperty('--stroke-color',e.target.value);
@@ -222,11 +238,16 @@ body{padding-top:46px}
document.getElementById('ease-sel').addEventListener('change',e=>{
document.documentElement.style.setProperty('--fill-ease',e.target.value);
});
- document.getElementById('dir-sel').addEventListener('change',applyDir);
+ document.getElementById('dir-sel').addEventListener('change',play);
+ document.getElementById('loop-tog').addEventListener('change',e=>{
+ if(e.target.checked)play();else clearTimeout(loopTimer);
+ });
document.getElementById('text-inp').addEventListener('input',e=>{
- applyText(e.target.value.toUpperCase()||'OUTLINE');reset();
+ applyText(e.target.value.toUpperCase()||'OUTLINE');play();
});
+ window.addEventListener('resize',fitText);
+ fitText();
play();
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/05-text-typography/rotate-word-carousel/index.html b/animations/05-text-typography/rotate-word-carousel/index.html
index f5d8d510..4f914b71 100644
--- a/animations/05-text-typography/rotate-word-carousel/index.html
+++ b/animations/05-text-typography/rotate-word-carousel/index.html
@@ -54,7 +54,7 @@
/* Multi-color classes */
.wc0{color:#58a6ff}.wc1{color:#56d364}.wc2{color:#d2a8ff}.wc3{color:#ffa657}.wc4{color:#f85149}
/* Word indicators */
- .word-dots{display:flex;gap:6px;margin-top:16px}
+ .word-dots{display:flex;flex-wrap:wrap;justify-content:center;gap:6px;margin-top:16px}
.word-dot{font-size:9px;padding:3px 8px;border-radius:3px;background:var(--ui-border);color:var(--ui-muted);letter-spacing:0.5px;transition:background .2s,color .2s}
.word-dot.active{background:var(--ui-accent);color:#000}
/* Panel */
@@ -72,7 +72,7 @@
textarea:focus{border-color:var(--ui-accent)}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
@media(max-width:600px){.layout{flex-direction:column;align-items:stretch}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:380px}}
@media(prefers-reduced-motion:reduce){.rot-word{transition:none!important;transform:none!important;opacity:1!important}}
@@ -138,7 +138,7 @@ Startups</textarea>
</aside>
</div>
<script>
- let wordIdx=0,timer=null;
+ let wordIdx=0,timer=null,run=0;
const rotWord=document.getElementById('rot-word');
const rotContainer=document.getElementById('rot-container');
const staticText=document.getElementById('static-text');
@@ -160,25 +160,30 @@ Startups</textarea>
function setColor(el,i){
el.classList.remove(...COLORS);
- if(document.getElementById('color-tog').checked)el.classList.add(COLORS[i%COLORS.length]);
+ if(document.getElementById('color-tog').checked){el.style.color='';el.classList.add(COLORS[i%COLORS.length]);}
else el.style.color='var(--word-color)';
}
function transitionTo(nextWord,nextIdx,done){
- const dir=getDir();
+ const dir=getDir(),id=run;
const outMap={up:'out-up',down:'out-down',left:'out-left',right:'out-right'};
const enterMap={up:'enter-below',down:'enter-above',left:'enter-right',right:'enter-left'};
rotWord.classList.add(outMap[dir]);
setTimeout(()=>{
+ if(id!==run)return; // a restart superseded this transition
// swap word
rotWord.textContent=nextWord;
setColor(rotWord,nextIdx);
+ // jump to the entry side without transitioning from the exit side
+ rotWord.style.transition='none';
rotWord.classList.remove(...outClasses,...enterClasses);
rotWord.classList.add(enterMap[dir]);
- // size container to new word
+ void rotWord.offsetWidth;
+ rotWord.style.transition='';
requestAnimationFrame(()=>requestAnimationFrame(()=>{
+ if(id!==run)return;
rotWord.classList.remove(...enterClasses);
- setTimeout(done,getDur()+50);
+ setTimeout(()=>{if(id===run)done()},getDur()+50);
}));
},getDur()+30);
}
@@ -193,9 +198,13 @@ Startups</textarea>
}
function start(){
- if(timer)clearTimeout(timer);wordIdx=0;
+ if(timer)clearTimeout(timer);wordIdx=0;run++;
const words=getWords();if(!words.length)return;
+ // snap back to rest without replaying the exit slide in reverse
+ rotWord.style.transition='none';
rotWord.classList.remove(...outClasses,...enterClasses);
+ void rotWord.offsetWidth;
+ rotWord.style.transition='';
rotWord.textContent=words[0];
setColor(rotWord,0);
staticText.textContent=document.getElementById('static-inp').value;
@@ -207,7 +216,7 @@ Startups</textarea>
document.getElementById('static-inp').addEventListener('input',e=>{staticText.textContent=e.target.value});
document.getElementById('words-inp').addEventListener('change',start);
document.getElementById('hold-sl').addEventListener('input',e=>{document.getElementById('hold-v').textContent=(e.target.value/1000).toFixed(1)+'s'});
- document.getElementById('dur-sl').addEventListener('input',e=>{document.getElementById('dur-v').textContent=e.target.value+'ms'});
+ document.getElementById('dur-sl').addEventListener('input',e=>{document.getElementById('dur-v').textContent=e.target.value+'ms';document.documentElement.style.setProperty('--rot-dur',e.target.value+'ms')});
document.getElementById('dir-sel').addEventListener('change',()=>{});
document.getElementById('color-tog').addEventListener('change',()=>setColor(rotWord,wordIdx));
diff --git a/animations/05-text-typography/scramble-text/index.html b/animations/05-text-typography/scramble-text/index.html
index 9526ba98..5e38241d 100644
--- a/animations/05-text-typography/scramble-text/index.html
+++ b/animations/05-text-typography/scramble-text/index.html
@@ -52,7 +52,7 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
input[type=text]{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:11px;padding:8px 10px;border-radius:4px;width:100%;min-height:44px;outline:none}
input[type=text]:focus{border-color:var(--ui-accent)}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
@@ -120,7 +120,9 @@ const CHARSETS={
matrix:'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン',
all:'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*<>{}[]'
};
-let cycleTimer=null,running=false;
+let cycleTimer=null,running=false,timers=[];
+const later=(fn,ms)=>timers.push(setTimeout(fn,ms));
+const reduceMotion=matchMedia('(prefers-reduced-motion: reduce)');
const out=document.getElementById('scramble-out');
const lockedCt=document.getElementById('locked-ct');
const remainCt=document.getElementById('remain-ct');
@@ -129,21 +131,30 @@ const cycleCt=document.getElementById('cycle-ct');
function randChar(charset){return charset[Math.floor(Math.random()*charset.length)]}
function scramble(){
- if(cycleTimer)clearInterval(cycleTimer);
+ // Kill every timer from the previous run so a replay never inherits stale settles, clears or loop chains
+ clearInterval(cycleTimer);cycleTimer=null;
+ timers.forEach(clearTimeout);timers=[];
running=true;
const text=document.getElementById('text-inp').value.toUpperCase();
const charset=CHARSETS[document.getElementById('charset-sel').value];
const cycleMs=+document.getElementById('cyc-sl').value;
const settleMs=+document.getElementById('settle-sl').value;
+ const reduce=reduceMotion.matches;
cycleCt.textContent=cycleMs+'ms';
// Build span per char
out.innerHTML='';
const spans=[];
- text.split('').forEach(c=>{
+ text.split('').forEach((c,i)=>{
if(c===' '){const sp=document.createElement('span');sp.className='sp';sp.setAttribute('aria-hidden','true');out.appendChild(sp);spans.push(null);return;}
- const s=document.createElement('span');s.className='char scrambling';s.textContent=randChar(charset);out.appendChild(s);spans.push(s);
+ const s=document.createElement('span');s.className=reduce?'char locked':'char scrambling';s.textContent=reduce?text[i]:randChar(charset);out.appendChild(s);spans.push(s);
});
+ const total=spans.filter(Boolean).length;
+
+ // Reduced motion (or nothing to decode): show the decoded text immediately, no cycling
+ if(reduce||!total){
+ out.setAttribute('aria-label',text);lockedCt.textContent=total;remainCt.textContent='0';running=false;return;
+ }
out.setAttribute('aria-label','Loading: '+text);
const locked=new Array(text.length).fill(false);
@@ -152,14 +163,15 @@ function scramble(){
// Settle each char after staggered delay
spans.forEach((s,i)=>{
if(!s)return;
- setTimeout(()=>{
+ later(()=>{
s.textContent=text[i];s.classList.remove('scrambling');s.classList.add('locked');
locked[i]=true;lockedCount++;
lockedCt.textContent=lockedCount;
- remainCt.textContent=spans.filter(Boolean).length-lockedCount;
- if(lockedCount===spans.filter(Boolean).length){
+ remainCt.textContent=total-lockedCount;
+ if(lockedCount===total){
+ clearInterval(cycleTimer);cycleTimer=null;
running=false;out.setAttribute('aria-label',text);
- if(document.getElementById('loop-tog').checked)setTimeout(scramble,1200);
+ if(document.getElementById('loop-tog').checked)later(scramble,1200);
}
},settleMs*i+settleMs);
});
@@ -169,16 +181,14 @@ function scramble(){
spans.forEach((s,i)=>{if(s&&!locked[i])s.textContent=randChar(charset);});
},cycleMs);
- const total=spans.filter(Boolean).length;
const totalTime=settleMs*total+settleMs;
- setTimeout(()=>clearInterval(cycleTimer),totalTime+cycleMs*2);
+ const thisTimer=cycleTimer;
+ later(()=>{if(cycleTimer===thisTimer){clearInterval(cycleTimer);cycleTimer=null;}},totalTime+cycleMs*2);
remainCt.textContent=total;lockedCt.textContent='0';
}
-document.getElementById('replay-btn').addEventListener('click',()=>{
- clearInterval(cycleTimer);running=false;scramble();
-});
+document.getElementById('replay-btn').addEventListener('click',scramble);
document.getElementById('cyc-sl').addEventListener('input',e=>document.getElementById('cyc-v').textContent=e.target.value+'ms');
document.getElementById('settle-sl').addEventListener('input',e=>document.getElementById('settle-v').textContent=e.target.value+'ms');
document.getElementById('text-inp').addEventListener('keydown',e=>{if(e.key==='Enter')scramble()});
diff --git a/animations/05-text-typography/text-clip-path-reveal/index.html b/animations/05-text-typography/text-clip-path-reveal/index.html
index 98cbda91..40a47305 100644
--- a/animations/05-text-typography/text-clip-path-reveal/index.html
+++ b/animations/05-text-typography/text-clip-path-reveal/index.html
@@ -30,7 +30,7 @@
header h1{font-family:var(--disp);font-weight:700;font-size:clamp(11px,1.8vw,15px);letter-spacing:-.01em}
header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
.layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:#08080a;display:flex;align-items:center;justify-content:center;padding:clamp(24px,4vw,48px)}
+ .stage{flex:1;min-width:0;min-height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:#08080a;display:flex;align-items:center;justify-content:center;padding:clamp(24px,4vw,48px)}
.headline{display:flex;flex-direction:column;gap:4px;overflow:visible}
.line-wrap{overflow:hidden;line-height:1.15}
.line-text{
@@ -57,11 +57,11 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
textarea{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px;border-radius:4px;width:100%;resize:vertical;min-height:72px;line-height:1.5;outline:none}
textarea:focus{border-color:var(--ui-accent)}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:360px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:360px}}
@media(prefers-reduced-motion:reduce){.line-text{clip-path:inset(0)!important;transition:none!important}}
</style>
<style id="ah-inject">
@@ -143,7 +143,7 @@ Always.</textarea>
}
function reveal(){
- if(loopTimer)clearTimeout(loopTimer);
+ if(loopTimer){clearTimeout(loopTimer);loopTimer=null}
const dur=+document.getElementById('dur-sl').value;
const stag=+document.getElementById('stag-sl').value;
document.documentElement.style.setProperty('--line-dur',dur+'ms');
@@ -162,10 +162,17 @@ Always.</textarea>
}
document.getElementById('replay-btn').addEventListener('click',reveal);
- document.getElementById('dur-sl').addEventListener('input',e=>document.getElementById('dur-v').textContent=e.target.value+'ms');
+ document.getElementById('dur-sl').addEventListener('input',e=>{
+ document.getElementById('dur-v').textContent=e.target.value+'ms';
+ document.documentElement.style.setProperty('--line-dur',e.target.value+'ms');
+ });
document.getElementById('stag-sl').addEventListener('input',e=>document.getElementById('stag-v').textContent=e.target.value+'ms');
document.getElementById('dir-sel').addEventListener('change',reveal);
document.getElementById('ease-sel').addEventListener('change',reveal);
+ document.getElementById('loop-tog').addEventListener('change',e=>{
+ if(e.target.checked){reveal();return}
+ if(loopTimer){clearTimeout(loopTimer);loopTimer=null}
+ });
reveal();
</script>
diff --git a/animations/05-text-typography/text-gradient-animation/index.html b/animations/05-text-typography/text-gradient-animation/index.html
index 258a02f4..91235e20 100644
--- a/animations/05-text-typography/text-gradient-animation/index.html
+++ b/animations/05-text-typography/text-gradient-animation/index.html
@@ -30,7 +30,7 @@
header h1{font-family:var(--disp);font-weight:700;font-size:clamp(11px,1.8vw,15px);letter-spacing:-.01em}
header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
.layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:#08080a;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:32px;padding:32px}
+ .stage{flex:1;min-width:0;min-height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:#08080a;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:32px;padding:32px}
/* Gradient text base */
.grad-text{
font-family:Georgia,'Times New Roman',serif;
@@ -45,6 +45,7 @@
animation:grad-flow var(--grad-dur) linear infinite;
display:block;
text-align:center;
+ max-width:100%;overflow-wrap:anywhere;
-webkit-user-select:none;user-select:none
}
/* Linear */
@@ -74,8 +75,8 @@
input[type=text]{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:11px;padding:8px 10px;border-radius:4px;width:100%;min-height:44px;outline:none}
input[type=text]:focus{border-color:var(--ui-accent)}
.color-row{display:flex;gap:8px;align-items:center;font-size:10px;color:var(--ui-muted)}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0;flex-shrink:0}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:400px}:root{--grad-size:64px}}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0;flex-shrink:0}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:400px}:root{--grad-size:64px}}
@media(prefers-reduced-motion:reduce){.grad-text{animation:none!important;background-position:0% 50%!important}}
</style>
<style id="ah-inject">
@@ -114,7 +115,7 @@ body{padding-top:46px}
<option value="grad-custom">Two-color custom</option>
</select>
<div class="lbl">Speed</div>
- <div class="sr"><input type="range" id="spd-sl" min="10" max="100" value="40" step="5"><span class="sv" id="spd-v">4s</span></div>
+ <div class="sr"><input type="range" id="spd-sl" min="10" max="100" value="40" step="5"><span class="sv" id="spd-v">4.0s</span></div>
<div class="lbl">Font Size</div>
<div class="sr"><input type="range" id="size-sl" min="32" max="160" value="120" step="8"><span class="sv" id="size-v">120px</span></div>
<div class="lbl">Custom Colors</div>
@@ -142,10 +143,19 @@ body{padding-top:46px}
document.getElementById('spd-v').textContent=v.toFixed(1)+'s';
document.documentElement.style.setProperty('--grad-dur',v+'s');
});
- document.getElementById('size-sl').addEventListener('input',e=>{
+ const sizeSl=document.getElementById('size-sl');
+ sizeSl.addEventListener('input',e=>{
document.getElementById('size-v').textContent=e.target.value+'px';
document.documentElement.style.setProperty('--grad-size',e.target.value+'px');
});
+ // The mobile media query shrinks --grad-size; keep the slider and readout in sync with it,
+ // including when the viewport crosses the breakpoint after load (rotation, resize).
+ const syncSize=()=>{
+ sizeSl.value=parseInt(getComputedStyle(gradText).fontSize,10);
+ document.getElementById('size-v').textContent=sizeSl.value+'px';
+ };
+ syncSize();
+ matchMedia('(max-width:600px)').addEventListener('change',syncSize);
document.getElementById('text-inp').addEventListener('input',e=>{
gradText.textContent=e.target.value||'Flow';
});
diff --git a/animations/05-text-typography/text-morphing/index.html b/animations/05-text-typography/text-morphing/index.html
index 855acbc8..c0a14836 100644
--- a/animations/05-text-typography/text-morphing/index.html
+++ b/animations/05-text-typography/text-morphing/index.html
@@ -30,7 +30,7 @@
header h1{font-family:var(--disp);font-weight:700;font-size:clamp(11px,1.8vw,15px);letter-spacing:-.01em}
header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
.layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:#08080a;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:20px;padding:32px}
+ .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:#08080a;overflow:hidden;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:20px;padding:32px}
.morph-label{font-size:10px;letter-spacing:3px;text-transform:uppercase;color:var(--ui-muted)}
/* Word display area */
.morph-stage{height:clamp(80px,12vw,130px);display:flex;align-items:center;justify-content:center;overflow:visible;position:relative;min-width:200px}
@@ -69,9 +69,9 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
textarea{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px;border-radius:4px;width:100%;resize:vertical;min-height:88px;line-height:1.5;outline:none}
textarea:focus{border-color:var(--ui-accent)}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:400px}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:400px}}
@media(prefers-reduced-motion:reduce){.morph-char{transition:none!important;transform:none!important;opacity:1!important}}
</style>
<style id="ah-inject">
@@ -129,7 +129,7 @@ SOUND</textarea>
</aside>
</div>
<script>
- let wordIdx=0,morphTimer=null,running=false;
+ let wordIdx=0,morphTimer=null,running=false,gen=0;
const wordEl=document.getElementById('current-word');
const dotsEl=document.getElementById('dots');
const curWordKv=document.getElementById('cur-word-kv');
@@ -178,7 +178,8 @@ SOUND</textarea>
});
const exitDur=dur+(stag*(fromChars.length-1));
- setTimeout(()=>{
+ const myGen=gen;
+ morphTimer=setTimeout(()=>{
// Build new word off-screen
wordEl.innerHTML='';
const enterDir={up:'enter-from-below',down:'enter-from-above',left:'enter-from-right',right:'enter-from-left'}[dir];
@@ -190,9 +191,10 @@ SOUND</textarea>
});
// Animate in
requestAnimationFrame(()=>requestAnimationFrame(()=>{
+ if(myGen!==gen)return; // a restart happened while we waited for paint
toChars.forEach(c=>{c.classList.remove('enter-from-below','enter-from-above','enter-from-left','enter-from-right');});
const enterDur=dur+(stag*(toChars.length-1));
- setTimeout(done,enterDur+50);
+ morphTimer=setTimeout(done,enterDur+50);
}));
},exitDur+60);
}
@@ -201,6 +203,9 @@ SOUND</textarea>
const words=getWords();
if(words.length<2)return;
running=true;
+ if(wordIdx>=words.length)wordIdx=0; // word list was shortened mid-cycle
+ if(wordEl.textContent!==words[wordIdx])showWord(words[wordIdx]); // list edited mid-cycle: keep display, dots and readout in sync
+ if(dotsEl.children.length!==words.length)buildDots(words);
updateDots(wordIdx);
curWordKv.textContent=words[wordIdx];
@@ -215,14 +220,15 @@ SOUND</textarea>
}
function start(){
- if(morphTimer)clearTimeout(morphTimer);running=false;wordIdx=0;
- const words=getWords();if(!words.length)return;
+ if(morphTimer)clearTimeout(morphTimer);running=false;wordIdx=0;gen++;
+ const words=getWords();
+ if(!words.length){wordEl.innerHTML='';dotsEl.innerHTML='';curWordKv.textContent='—';return}
buildDots(words);showWord(words[0]);curWordKv.textContent=words[0];
- setTimeout(cycle,100);
+ morphTimer=setTimeout(cycle,100);
}
document.getElementById('restart-btn').addEventListener('click',start);
- document.getElementById('dur-sl').addEventListener('input',e=>{document.getElementById('dur-v').textContent=e.target.value+'ms'});
+ document.getElementById('dur-sl').addEventListener('input',e=>{document.getElementById('dur-v').textContent=e.target.value+'ms';document.documentElement.style.setProperty('--morph-dur',e.target.value+'ms')});
document.getElementById('pause-sl').addEventListener('input',e=>{document.getElementById('pause-v').textContent=(e.target.value/1000).toFixed(1)+'s'});
document.getElementById('stag-sl').addEventListener('input',e=>{document.getElementById('stag-v').textContent=e.target.value+'ms'});
diff --git a/animations/05-text-typography/text-on-path/index.html b/animations/05-text-typography/text-on-path/index.html
index b33e7c8a..c411f299 100644
--- a/animations/05-text-typography/text-on-path/index.html
+++ b/animations/05-text-typography/text-on-path/index.html
@@ -52,7 +52,7 @@
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
.div{height:1px;background:var(--ui-border)}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:340px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:340px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -112,18 +112,29 @@ const PATHS={
arc:'M20,300 Q320,20 620,300',
circle:'M320,60 a120,120 0 1,1 -0.1,0'
};
-let offset=0,speed=0.4,raf=null;
+const inp=document.getElementById('text-inp');
+let offset=0,speed=0.4,raf=null,unit=100;
+// Glyphs past the end of the path are not drawn, so repeat the string until it
+// covers the path plus one extra copy, then wrap the offset over that one copy.
+// One copy's length is measured as (two copies - one copy) so collapsed
+// leading/trailing spaces cancel out and the wrap point lines up exactly.
+function measure(){ const n=tp.getNumberOfChars(); return n?tp.getSubStringLength(0,n):0; }
+function fill(){
+ const s=inp.value||' ';
+ tp.textContent=s; const one=measure();
+ tp.textContent=s+s; const two=measure();
+ unit=Math.max((two-one)/curve.getTotalLength()*100,1);
+ tp.textContent=s.repeat(Math.ceil(100/unit)+1);
+}
function loop(){
- offset=(offset+speed)%100;
- tp.setAttribute('startOffset',offset+'%');
+ offset=(offset+speed)%unit;
+ tp.setAttribute('startOffset',(offset-unit)+'%');
raf=requestAnimationFrame(loop);
}
function start(){ if(reduce||raf)return; raf=requestAnimationFrame(loop); }
-document.getElementById('text-inp').addEventListener('input',e=>{
- tp.textContent=e.target.value||' ';
-});
+inp.addEventListener('input',fill);
document.getElementById('spd-sl').addEventListener('input',e=>{
speed=+e.target.value/100;
document.getElementById('spd-sv').textContent=e.target.value;
@@ -136,8 +147,10 @@ document.querySelectorAll('#shape button').forEach(b=>{
document.querySelectorAll('#shape button').forEach(x=>x.classList.remove('on'));
b.classList.add('on');
curve.setAttribute('d',PATHS[b.dataset.shape]);
+ fill();
});
});
+fill();
start();
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/05-text-typography/typewriter-effect/index.html b/animations/05-text-typography/typewriter-effect/index.html
index 64ac0ad5..e45f6b71 100644
--- a/animations/05-text-typography/typewriter-effect/index.html
+++ b/animations/05-text-typography/typewriter-effect/index.html
@@ -55,10 +55,10 @@
textarea{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px;border-radius:4px;width:100%;resize:vertical;min-height:72px;line-height:1.5}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:360px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:360px}input[type=color]{height:44px}}
@media(prefers-reduced-motion:reduce){.cursor{animation:none!important;opacity:1!important}}
</style>
<style id="ah-inject">
@@ -160,6 +160,7 @@ body{padding-top:46px}
const words=text.trim().split(' ');
const deleteFrom=Math.max(text.length-words[words.length-1].length-1,Math.floor(text.length*0.6));
type(text,()=>{
+ running=true;
let i=text.length;
function del(){
if(i>deleteFrom){
@@ -172,13 +173,14 @@ body{padding-top:46px}
function retype(){
if(j<=rest.length+deleteFrom){
typeOut.firstChild?.nodeType===3&&(typeOut.firstChild.textContent=(text.substring(0,deleteFrom)+rest.substring(0,j-deleteFrom)));
+ statChars.textContent=j;
j++;timer=setTimeout(retype,jitter(getSpeed()));
}else{running=false;afterType();}
}
retype();
}
}
- setTimeout(del,500);
+ timer=setTimeout(del,500);
});
}
@@ -192,15 +194,22 @@ body{padding-top:46px}
}
function afterType(){
- if(document.getElementById('loop-tog').checked)setTimeout(start,1200);
+ if(document.getElementById('loop-tog').checked)timer=setTimeout(()=>{if(document.getElementById('loop-tog').checked)start()},1200);
}
- document.getElementById('cursor-sel').addEventListener('change',()=>{if(!running)start()});
+ document.getElementById('cursor-sel').addEventListener('change',e=>{
+ const c=typeOut.querySelector('.cursor');
+ if(c)c.className='cursor '+e.target.value;
+ });
document.getElementById('cursor-color').addEventListener('input',e=>{
document.documentElement.style.setProperty('--cursor-color',e.target.value);
});
document.getElementById('spd-sl').addEventListener('input',e=>{
document.getElementById('spd-v').textContent=e.target.value+'ms';
+ if(!running)statSpeed.textContent=e.target.value+'ms';
+ });
+ document.getElementById('loop-tog').addEventListener('change',e=>{
+ if(e.target.checked&&!running)start();
});
document.getElementById('replay-btn').addEventListener('click',()=>{
if(timer)clearTimeout(timer);running=false;start();
diff --git a/animations/05-text-typography/variable-font-morph/index.html b/animations/05-text-typography/variable-font-morph/index.html
index 0fa3363d..32121255 100644
--- a/animations/05-text-typography/variable-font-morph/index.html
+++ b/animations/05-text-typography/variable-font-morph/index.html
@@ -30,7 +30,7 @@
header h1{font-family:var(--disp);font-weight:700;font-size:clamp(16px,2.2vw,22px);letter-spacing:-.01em}
header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
.layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:#04060c;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:24px;padding:32px}
+ .stage{flex:1;min-width:0;min-height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:#04060c;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:24px;padding:32px}
.vf-label{font-size:10px;letter-spacing:3px;text-transform:uppercase;color:var(--ui-muted)}
.vf-text{
font-family:'Recursive','Segoe UI Variable',system-ui,'Segoe UI',sans-serif;
@@ -38,11 +38,13 @@
line-height:1;
color:#fff;
letter-spacing:-0.02em;
+ max-width:100%;overflow-wrap:anywhere;text-align:center;
/* wght/slnt are standard axes system-ui exposes; font-weight + skewX are the
universal fallback so the morph is visible even without a variable font. */
font-weight:var(--wght);
font-variation-settings:'wght' var(--wght),'CASL' var(--CASL),'slnt' var(--slnt);
- transform:skewX(calc(var(--slnt) * -1deg));
+ /* slnt is negative for a right-leaning (italic) slant, and so is skewX. */
+ transform:skewX(calc(var(--slnt) * 1deg));
transition:font-variation-settings 600ms cubic-bezier(.4,0,.2,1),font-weight 600ms cubic-bezier(.4,0,.2,1),transform 600ms cubic-bezier(.4,0,.2,1);
-webkit-user-select:none;user-select:none
}
@@ -174,7 +176,7 @@ document.getElementById('text-inp').addEventListener('input',e=>{
});
document.querySelectorAll('.preset-btn').forEach(btn=>{
btn.addEventListener('click',()=>{
- clearInterval(autoTimer);autoTimer=null;
+ clearInterval(autoTimer);autoTimer=null;document.getElementById('auto-btn').textContent='▶ Auto-morph presets';
apply(+btn.dataset.wght,+btn.dataset.casl*100,+btn.dataset.slnt);
});
});
diff --git a/animations/05-text-typography/wavy-text/index.html b/animations/05-text-typography/wavy-text/index.html
index ca146983..260a9342 100644
--- a/animations/05-text-typography/wavy-text/index.html
+++ b/animations/05-text-typography/wavy-text/index.html
@@ -52,7 +52,7 @@
input[type=text]{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:11px;padding:8px 10px;border-radius:4px;width:100%;min-height:44px;outline:none}
input[type=text]:focus{border-color:var(--ui-accent)}
.div{height:1px;background:var(--ui-border)}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:340px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:340px}}
@media(prefers-reduced-motion:reduce){
.wave-text span{animation:none!important;transform:none!important}
}
@@ -108,8 +108,17 @@ function build(str){
s.setAttribute('aria-hidden','true');
wave.appendChild(s);
});
+ fit();
+}
+// Shrink the type when a long string would spill past the stage edges.
+const stage=document.querySelector('.stage');
+function fit(){
+ wave.style.fontSize='';
+ const room=stage.clientWidth-48;
+ if(wave.offsetWidth>room) wave.style.fontSize=parseFloat(getComputedStyle(wave).fontSize)*room/wave.offsetWidth+'px';
}
build('Wavy');
+addEventListener('resize',fit);
document.getElementById('text-inp').addEventListener('input',e=>build(e.target.value||' '));
document.getElementById('amp-sl').addEventListener('input',e=>{
@@ -117,7 +126,7 @@ document.getElementById('amp-sl').addEventListener('input',e=>{
document.getElementById('amp-sv').textContent=e.target.value+'px';
});
document.getElementById('spd-sl').addEventListener('input',e=>{
- const dur=(11-+e.target.value)*0.28;
+ const dur=(11-+e.target.value)*0.32;
root.style.setProperty('--dur',dur.toFixed(1)+'s');
document.getElementById('spd-sv').textContent=dur.toFixed(1)+'s';
});
diff --git a/animations/06-3d-advanced/2-5d-pseudo-3d/index.html b/animations/06-3d-advanced/2-5d-pseudo-3d/index.html
index d734a087..1d5f9d70 100644
--- a/animations/06-3d-advanced/2-5d-pseudo-3d/index.html
+++ b/animations/06-3d-advanced/2-5d-pseudo-3d/index.html
@@ -30,7 +30,7 @@
header h1{font-family:var(--disp);font-weight:700;font-size:clamp(11px,1.8vw,15px);letter-spacing:-.01em}
header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
.layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;overflow:hidden;position:relative;cursor:none}
+ .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;overflow:hidden;position:relative;cursor:none;touch-action:pan-y}
/* 3D scene container */
.scene{width:100%;height:100%;position:relative;perspective:800px;perspective-origin:50% 50%;overflow:hidden}
.scene-inner{width:100%;height:100%;position:relative;transform-style:preserve-3d;transform:translateZ(0);transition:transform 0ms linear}
@@ -75,7 +75,7 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
@media(max-width:600px){.layout{flex-direction:column;align-items:stretch}aside{width:100%}:root{--stage-h:420px}.stage{flex:none}}
@media(prefers-reduced-motion:reduce){.scene-inner{transition:none!important}}
@@ -206,21 +206,15 @@ function applyParallax(normX,normY){
});
}
-stage.addEventListener('mousemove',e=>{
+stage.addEventListener('pointermove',e=>{
const r=stage.getBoundingClientRect();
mx=(e.clientX-r.left)/r.width-.5;
my=(e.clientY-r.top)/r.height-.5;
- cursor.style.display='block';cursor.style.left=(e.clientX-r.left)+'px';cursor.style.top=(e.clientY-r.top)+'px';
+ if(e.pointerType==='mouse'){cursor.style.display='block';cursor.style.left=(e.clientX-r.left)+'px';cursor.style.top=(e.clientY-r.top)+'px';}
mxV.textContent=(mx*100).toFixed(0)+'%';
if(mode==='mouse')applyParallax(mx,my);
});
-stage.addEventListener('mouseleave',()=>{cursor.style.display='none'});
-stage.addEventListener('touchmove',e=>{
- const r=stage.getBoundingClientRect();
- mx=(e.touches[0].clientX-r.left)/r.width-.5;
- my=(e.touches[0].clientY-r.top)/r.height-.5;
- if(mode==='mouse')applyParallax(mx,my);
-},{passive:true});
+stage.addEventListener('pointerleave',()=>{cursor.style.display='none'});
function autoLoop(t){
raf=requestAnimationFrame(autoLoop);
@@ -230,8 +224,11 @@ function autoLoop(t){
document.getElementById('mode-sel').addEventListener('change',e=>{
mode=e.target.value;
- if(mode==='auto'){if(!raf)raf=requestAnimationFrame(autoLoop);}
- else{if(raf){cancelAnimationFrame(raf);raf=null;}}
+ if(raf){cancelAnimationFrame(raf);raf=null;}
+ if(mode==='auto'){
+ if(motionOk)raf=requestAnimationFrame(autoLoop);
+ else applyParallax(.25,.15); // reduced motion: hold a static camera offset instead of panning
+ }
});
document.getElementById('str-sl').addEventListener('input',e=>{
strength=+e.target.value;document.getElementById('str-v').textContent=strength+'px';
@@ -239,7 +236,7 @@ document.getElementById('str-sl').addEventListener('input',e=>{
document.getElementById('labels-tog').addEventListener('change',e=>{
document.querySelectorAll('.depth-label').forEach(d=>d.style.display=e.target.checked?'block':'none');
});
-document.getElementById('reset-btn').addEventListener('click',()=>{applyParallax(0,0)});
+document.getElementById('reset-btn').addEventListener('click',()=>{mx=0;my=0;mxV.textContent='—';applyParallax(0,0)});
// Hide labels by default
document.querySelectorAll('.depth-label').forEach(d=>d.style.display='none');
diff --git a/animations/06-3d-advanced/3d-model-orbit/index.html b/animations/06-3d-advanced/3d-model-orbit/index.html
index 5e80fb58..21ce7708 100644
--- a/animations/06-3d-advanced/3d-model-orbit/index.html
+++ b/animations/06-3d-advanced/3d-model-orbit/index.html
@@ -30,7 +30,7 @@
header h1{font-family:var(--disp);font-weight:700;font-size:clamp(11px,1.8vw,15px);letter-spacing:-.01em}
header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
.layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;overflow:hidden;position:relative}
+ .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;overflow:hidden;position:relative;touch-action:pan-y}
canvas{display:block;width:100%;height:100%}
.hud{position:absolute;top:8px;left:8px;right:8px;display:flex;justify-content:space-between;pointer-events:none}
.fps-badge,.obj-badge{font-size:9px;color:rgba(255,255,255,.5);background:rgba(0,0,0,.4);padding:3px 8px;border-radius:4px;letter-spacing:.5px}
@@ -44,11 +44,10 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}
button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:380px}}
- @media(prefers-reduced-motion:reduce){canvas{display:none}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}.stage{flex:0 0 auto}aside{width:100%}:root{--stage-h:380px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -197,7 +196,7 @@ function makeTetra(){
// ─── WebGL setup ───────────────────────────────────────────────────────────
const stage=document.getElementById('stage'),cvs=document.getElementById('cvs');
const fpsEl=document.getElementById('fps'),objBadge=document.getElementById('obj-badge');
-let W,H,gl,prog,posBuf,nrmBuf,idxBuf,idxCount;
+let W,H,gl,prog,posBuf,nrmBuf,idxBuf,lineBuf,idxCount,lineCount;
let raf=null,paused=false,lastT=0,rx=.3,ry=0;
let MODE='orbit',WIRE=false,DIST=3,SX=.2,SY=.8,COLOR=[88/255,166/255,255/255];
let mouseNX=0,mouseNY=0;
@@ -211,17 +210,21 @@ function init(){
gl.attachShader(prog,sh(gl.FRAGMENT_SHADER,FS));
gl.linkProgram(prog);gl.useProgram(prog);
gl.enable(gl.DEPTH_TEST);gl.clearColor(.024,.039,.063,1);
- posBuf=gl.createBuffer();nrmBuf=gl.createBuffer();idxBuf=gl.createBuffer();
+ posBuf=gl.createBuffer();nrmBuf=gl.createBuffer();idxBuf=gl.createBuffer();lineBuf=gl.createBuffer();
loadGeometry('cube');
}
function loadGeometry(name){
const geo={cube:makeCube,sphere:makeSphere,torus:makeTorus,tetra:makeTetra}[name]();
+ // Wireframe edges: each triangle (a,b,c) becomes three line segments
+ const lines=[];
+ for(let i=0;i<geo.idx.length;i+=3){const a=geo.idx[i],b=geo.idx[i+1],c=geo.idx[i+2];lines.push(a,b,b,c,c,a);}
gl.bindBuffer(gl.ARRAY_BUFFER,posBuf);gl.bufferData(gl.ARRAY_BUFFER,geo.pos,gl.STATIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER,nrmBuf);gl.bufferData(gl.ARRAY_BUFFER,geo.nrm,gl.STATIC_DRAW);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,idxBuf);gl.bufferData(gl.ELEMENT_ARRAY_BUFFER,geo.idx,gl.STATIC_DRAW);
- idxCount=geo.idx.length;
- objBadge.textContent=name.charAt(0).toUpperCase()+name.slice(1);
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,lineBuf);gl.bufferData(gl.ELEMENT_ARRAY_BUFFER,new Uint16Array(lines),gl.STATIC_DRAW);
+ idxCount=geo.idx.length;lineCount=lines.length;
+ objBadge.textContent={cube:'Cube',sphere:'Sphere',torus:'Torus',tetra:'Tetrahedron'}[name];
}
function resize(){W=cvs.width=stage.clientWidth;H=cvs.height=stage.clientHeight;if(gl)gl.viewport(0,0,W,H);}
@@ -233,17 +236,10 @@ function setAttr(name,buf,size){
}
function u(n){return gl.getUniformLocation(prog,n);}
-function render(ts){
- if(paused){raf=null;return;}
- raf=requestAnimationFrame(render);
- const dt=ts-lastT;if(dt<16)return;
- fpsEl.textContent=Math.round(1000/(dt||16))+' fps';lastT=ts;
- if(MODE==='orbit'){ry+=SY*.01;rx+=SX*.01*(Math.sin(ts*.0003)*.5+.5);}
- else{rx=mouseNY*1.2;ry=mouseNX*1.5;}
+function draw(){
gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT);
gl.useProgram(prog);
setAttr('aPos',posBuf,3);setAttr('aNorm',nrmBuf,3);
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,idxBuf);
const P=persp(Math.PI/4,W/H,.1,20);
const T=trans(0,0,-DIST);
const M=mul(mul(T,rotY(ry)),rotX(rx));
@@ -253,30 +249,41 @@ function render(ts){
gl.uniform3fv(u('uCol'),COLOR);
gl.uniform3f(u('uLight'),2,3,4);
gl.uniform1i(u('uWire'),WIRE?1:0);
- if(WIRE){
- // Draw wireframe by drawing lines — use LINE_STRIP approximation
- gl.drawElements(gl.TRIANGLES,idxCount,gl.UNSIGNED_SHORT,0);
- }else{
- gl.drawElements(gl.TRIANGLES,idxCount,gl.UNSIGNED_SHORT,0);
- }
+ if(WIRE){gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,lineBuf);gl.drawElements(gl.LINES,lineCount,gl.UNSIGNED_SHORT,0);}
+ else{gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,idxBuf);gl.drawElements(gl.TRIANGLES,idxCount,gl.UNSIGNED_SHORT,0);}
+}
+
+function render(ts){
+ if(paused){raf=null;return;}
+ raf=requestAnimationFrame(render);
+ const dt=ts-lastT;if(dt<16)return;
+ fpsEl.textContent=Math.round(1000/(dt||16))+' fps';lastT=ts;
+ if(MODE==='orbit'){ry+=SY*.01;rx+=SX*.01*(Math.sin(ts*.0003)*.5+.5);}
+ else{rx=mouseNY*1.2;ry=mouseNX*1.5;}
+ draw();
}
init();resize();
-if(motionOk){lastT=performance.now();raf=requestAnimationFrame(render);}
+if(!gl){fpsEl.textContent='WebGL unavailable';}
+else if(motionOk){lastT=performance.now();raf=requestAnimationFrame(render);}
+else{draw();} // reduced motion: one static frame, object stays visible
-stage.addEventListener('mousemove',e=>{const r=cvs.getBoundingClientRect();mouseNX=(e.clientX-r.left)/r.width*2-1;mouseNY=(e.clientY-r.top)/r.height*2-1;});
-stage.addEventListener('touchmove',e=>{const r=cvs.getBoundingClientRect();mouseNX=(e.touches[0].clientX-r.left)/r.width*2-1;mouseNY=(e.touches[0].clientY-r.top)/r.height*2-1;},{passive:true});
-window.addEventListener('resize',resize);
+stage.addEventListener('pointermove',e=>{
+ const r=cvs.getBoundingClientRect();mouseNX=(e.clientX-r.left)/r.width*2-1;mouseNY=(e.clientY-r.top)/r.height*2-1;
+ if(gl&&!raf&&!paused&&MODE==='mouse'){rx=mouseNY*1.2;ry=mouseNX*1.5;draw();} // reduced motion: still follows the pointer
+});
+window.addEventListener('resize',()=>{resize();if(gl&&!raf)draw();});
document.getElementById('mode-sel').addEventListener('change',e=>MODE=e.target.value);
-document.getElementById('obj-sel').addEventListener('change',e=>{loadGeometry(e.target.value);rx=0;ry=0;});
+document.getElementById('obj-sel').addEventListener('change',e=>{if(!gl)return;loadGeometry(e.target.value);rx=0;ry=0;if(!raf)draw();});
document.getElementById('sx-sl').addEventListener('input',e=>{SX=e.target.value/10;document.getElementById('sx-v').textContent=SX.toFixed(1);});
document.getElementById('sy-sl').addEventListener('input',e=>{SY=e.target.value/10;document.getElementById('sy-v').textContent=SY.toFixed(1);});
-document.getElementById('cam-sl').addEventListener('input',e=>{DIST=e.target.value/10;document.getElementById('cam-v').textContent=DIST.toFixed(1);});
-document.getElementById('color-pick').addEventListener('input',e=>{const h=e.target.value;COLOR=[parseInt(h.slice(1,3),16)/255,parseInt(h.slice(3,5),16)/255,parseInt(h.slice(5,7),16)/255];});
-document.getElementById('wire-tog').addEventListener('change',e=>{WIRE=e.target.checked;});
+document.getElementById('cam-sl').addEventListener('input',e=>{DIST=e.target.value/10;document.getElementById('cam-v').textContent=DIST.toFixed(1);if(gl&&!raf)draw();});
+document.getElementById('color-pick').addEventListener('input',e=>{const h=e.target.value;COLOR=[parseInt(h.slice(1,3),16)/255,parseInt(h.slice(3,5),16)/255,parseInt(h.slice(5,7),16)/255];if(gl&&!raf)draw();});
+document.getElementById('wire-tog').addEventListener('change',e=>{WIRE=e.target.checked;if(gl&&!raf)draw();});
document.getElementById('pause-btn').addEventListener('click',()=>{
paused=!paused;document.getElementById('pause-btn').textContent=paused?'▶ Resume':'⏸ Pause';
+ if(raf){cancelAnimationFrame(raf);raf=null;} // never leave two loops running
if(!paused&&gl){lastT=performance.now();raf=requestAnimationFrame(render);}
});
</script>
diff --git a/animations/06-3d-advanced/canvas-particle-effect/index.html b/animations/06-3d-advanced/canvas-particle-effect/index.html
index 930014b2..a12253cb 100644
--- a/animations/06-3d-advanced/canvas-particle-effect/index.html
+++ b/animations/06-3d-advanced/canvas-particle-effect/index.html
@@ -44,11 +44,10 @@
.sv{width:40px;text-align:right;color:var(--ui-text)}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}
button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:380px}}
- @media(prefers-reduced-motion:reduce){canvas{display:none}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:380px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -135,7 +134,10 @@ function loop(t){
raf=requestAnimationFrame(loop);
const dt=t-lastT;if(dt<16){return;}lastT=t;
fps=Math.round(1000/(dt||16));fpsEl.textContent=fps+' fps';
+ draw();
+}
+function draw(){
if(TRAILS){ctx.fillStyle='rgba(6,10,16,.15)';ctx.fillRect(0,0,W,H);}
else{ctx.clearRect(0,0,W,H);}
@@ -169,16 +171,22 @@ function loop(t){
function start(){if(!paused&&!raf){lastT=performance.now();raf=requestAnimationFrame(loop);}}
-resize();spawn();start();
+// Lighter default on phones: O(n²) checks on a small, dense stage get expensive fast.
+if(innerWidth<=600){COUNT=250;document.getElementById('count-sl').value=COUNT;document.getElementById('count-v').textContent=COUNT;document.getElementById('p-count').textContent=COUNT;}
+resize();spawn();
+// Reduced motion: show one static frame; the user can still opt in with Resume.
+if(matchMedia('(prefers-reduced-motion:reduce)').matches){paused=true;document.getElementById('pause-btn').textContent='▶ Resume';draw();}
+else start();
stage.addEventListener('mousemove',e=>{const r=cvs.getBoundingClientRect();mouse.x=e.clientX-r.left;mouse.y=e.clientY-r.top;});
stage.addEventListener('mouseleave',()=>{mouse.x=-999;mouse.y=-999;});
stage.addEventListener('touchmove',e=>{const r=cvs.getBoundingClientRect();mouse.x=e.touches[0].clientX-r.left;mouse.y=e.touches[0].clientY-r.top;},{passive:true});
-window.addEventListener('resize',()=>{resize();spawn();});
+['touchend','touchcancel'].forEach(ev=>stage.addEventListener(ev,()=>{mouse.x=-999;mouse.y=-999;}));
+window.addEventListener('resize',()=>{resize();spawn();if(paused)draw();});
-document.getElementById('count-sl').addEventListener('input',e=>{COUNT=+e.target.value;document.getElementById('count-v').textContent=COUNT;document.getElementById('p-count').textContent=COUNT;spawn();});
+document.getElementById('count-sl').addEventListener('input',e=>{COUNT=+e.target.value;document.getElementById('count-v').textContent=COUNT;document.getElementById('p-count').textContent=COUNT;spawn();if(paused)draw();});
document.getElementById('dist-sl').addEventListener('input',e=>{DIST=+e.target.value;document.getElementById('dist-v').textContent=DIST+'px';});
-document.getElementById('spd-sl').addEventListener('input',e=>{SPD=e.target.value/10;document.getElementById('spd-v').textContent=SPD.toFixed(1);});
+document.getElementById('spd-sl').addEventListener('input',e=>{const n=e.target.value/10,k=n/SPD;SPD=n;particles.forEach(p=>{p.vx*=k;p.vy*=k;});document.getElementById('spd-v').textContent=SPD.toFixed(1);});
document.getElementById('force-sl').addEventListener('input',e=>{FORCE=e.target.value/10;document.getElementById('force-v').textContent=FORCE.toFixed(1);});
document.getElementById('color-pick').addEventListener('input',e=>{COLOR=e.target.value;});
document.getElementById('conn-tog').addEventListener('change',e=>{CONNECTIONS=e.target.checked;});
diff --git a/animations/06-3d-advanced/chromatic-aberration/index.html b/animations/06-3d-advanced/chromatic-aberration/index.html
index 86ab6435..09c45fbd 100644
--- a/animations/06-3d-advanced/chromatic-aberration/index.html
+++ b/animations/06-3d-advanced/chromatic-aberration/index.html
@@ -55,8 +55,8 @@
.ca-wrap.pulse .ca-b{animation:ca-pulse-b 2s ease-in-out infinite}
.ca-wrap.glitch .ca-r{animation:ca-glitch-r 4s step-end infinite}
.ca-wrap.glitch .ca-b{animation:ca-glitch-b 4s step-end infinite}
- @keyframes ca-pulse-r{0%,100%{transform:var(--r-t)}50%{transform:translate(calc(var(--ca-amt)*1.8),0) translate(calc(cos(var(--ca-angle))*1px),calc(sin(var(--ca-angle))*1px))}}
- @keyframes ca-pulse-b{0%,100%{transform:var(--b-t)}50%{transform:translate(calc(var(--ca-amt)*-1.8),0)}}
+ @keyframes ca-pulse-r{0%,100%{transform:var(--r-t)}50%{transform:translate(calc(cos(var(--ca-angle))*var(--ca-amt)*1.8),calc(sin(var(--ca-angle))*var(--ca-amt)*1.8))}}
+ @keyframes ca-pulse-b{0%,100%{transform:var(--b-t)}50%{transform:translate(calc(cos(var(--ca-angle))*var(--ca-amt)*-1.8),calc(sin(var(--ca-angle))*var(--ca-amt)*-1.8))}}
@keyframes ca-glitch-r{
0%,80%,100%{transform:var(--r-t)}
82%{transform:translate(calc(var(--ca-amt)*3),calc(var(--ca-amt)*-1))}
@@ -84,7 +84,7 @@
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
input[type=text]{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:11px;padding:8px 10px;border-radius:4px;width:100%;min-height:44px;outline:none}
input[type=text]:focus{border-color:var(--ui-accent)}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:380px}}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:380px}}
@media(prefers-reduced-motion:reduce){.ca-r,.ca-b{animation:none!important}}
</style>
<style id="ah-inject">
@@ -150,6 +150,15 @@ body{padding-top:46px}
bLayer.style.transform=`translate(${-dx}px,${-dy}px)`;
document.documentElement.style.setProperty('--r-t',`translate(${dx}px,${dy}px)`);
document.documentElement.style.setProperty('--b-t',`translate(${-dx}px,${-dy}px)`);
+ document.documentElement.style.setProperty('--ca-amt',amt+'px');
+ document.documentElement.style.setProperty('--ca-angle',angle+'deg');
+ }
+
+ function setBlur(v){
+ document.getElementById('blur-sl').value=v;
+ document.getElementById('blur-v').textContent=v+'px';
+ document.getElementById('blur-tog').checked=+v>0;
+ document.documentElement.style.setProperty('--ca-blur',v+'px');
}
function setText(t){
@@ -164,19 +173,13 @@ body{padding-top:46px}
document.getElementById('angle-sl').addEventListener('input',e=>{
angle=+e.target.value;document.getElementById('angle-v').textContent=angle+'°';applyOffset();
});
- document.getElementById('blur-sl').addEventListener('input',e=>{
- const v=e.target.value;document.getElementById('blur-v').textContent=v+'px';
- document.documentElement.style.setProperty('--ca-blur',v+'px');
- });
+ document.getElementById('blur-sl').addEventListener('input',e=>setBlur(e.target.value));
document.getElementById('mode-sel').addEventListener('change',e=>{
wrap.classList.remove('pulse','glitch');
if(e.target.value!=='static')wrap.classList.add(e.target.value);
applyOffset();
});
- document.getElementById('blur-tog').addEventListener('change',e=>{
- const v=e.target.checked?'1px':'0px';
- document.documentElement.style.setProperty('--ca-blur',v);
- });
+ document.getElementById('blur-tog').addEventListener('change',e=>setBlur(e.target.checked?1:0));
document.getElementById('text-inp').addEventListener('input',e=>setText(e.target.value));
applyOffset();
diff --git a/animations/06-3d-advanced/cloth-simulation/index.html b/animations/06-3d-advanced/cloth-simulation/index.html
index 0dda84a0..0f4b119f 100644
--- a/animations/06-3d-advanced/cloth-simulation/index.html
+++ b/animations/06-3d-advanced/cloth-simulation/index.html
@@ -31,7 +31,7 @@
header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
.layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
.stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;overflow:hidden;position:relative}
- canvas{display:block;width:100%;height:100%}
+ canvas{display:block;width:100%;height:100%;touch-action:none;cursor:grab}
.fps-badge{position:absolute;top:8px;right:8px;font-size:9px;color:rgba(255,255,255,.5);background:rgba(0,0,0,.4);padding:3px 8px;border-radius:4px}
aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
.note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
@@ -43,10 +43,9 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:400px}}
- @media(prefers-reduced-motion:reduce){canvas{display:none}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:400px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -104,7 +103,8 @@ body{padding-top:46px}
<script>
const cvs=document.getElementById('cvs'),ctx=cvs.getContext('2d');
const stage=document.getElementById('stage'),fpsEl=document.getElementById('fps');
-let W,H,paused=false,raf=null,lastT=0;
+// Reduced motion: start paused with a static frame; the user can opt in via Resume.
+let W,H,paused=matchMedia('(prefers-reduced-motion:reduce)').matches,raf=null,lastT=0;
let COLS=24,ROWS=18,GRAVITY=0.12,WIND=0.5,ITERS=4,PIN_MODE='top-corners';
let SHOW_VERTS=false,SHOW_CONS=false;
let pts=[],prev=[],pinned=[],constraints=[];
@@ -134,6 +134,7 @@ function initCloth(){
if(c<COLS){const rest=Math.hypot(pts[n(r,c+1)][0]-pts[n(r,c)][0],pts[n(r,c+1)][1]-pts[n(r,c)][1]);constraints.push([n(r,c),n(r,c+1),rest]);}
if(r<ROWS){const rest=Math.hypot(pts[n(r+1,c)][0]-pts[n(r,c)][0],pts[n(r+1,c)][1]-pts[n(r,c)][1]);constraints.push([n(r,c),n(r+1,c),rest]);}
}}
+ if(paused)draw(); // keep the canvas populated while the loop is stopped
}
function update(){
@@ -205,6 +206,7 @@ function loop(ts){
}
function start(){resize();initCloth();if(!paused&&!raf){lastT=performance.now();raf=requestAnimationFrame(loop);}}
+document.getElementById('pause-btn').textContent=paused?'▶ Resume':'⏸ Pause';
start();
// Drag interaction
@@ -213,12 +215,13 @@ function getClosestVertex(x,y,maxDist=30){
pts.forEach((p,i)=>{const d=Math.hypot(p[0]-x,p[1]-y);if(d<bd&&d<maxDist){bd=d;best=i;}});
return best;
}
-stage.addEventListener('mousedown',e=>{const r=cvs.getBoundingClientRect();dragIdx=getClosestVertex(e.clientX-r.left,e.clientY-r.top);dragMouse={x:e.clientX-r.left,y:e.clientY-r.top};});
-stage.addEventListener('mousemove',e=>{const r=cvs.getBoundingClientRect();dragMouse={x:e.clientX-r.left,y:e.clientY-r.top};});
-stage.addEventListener('mouseup',()=>dragIdx=-1);
-stage.addEventListener('touchstart',e=>{const r=cvs.getBoundingClientRect();dragIdx=getClosestVertex(e.touches[0].clientX-r.left,e.touches[0].clientY-r.top);},{passive:true});
-stage.addEventListener('touchmove',e=>{const r=cvs.getBoundingClientRect();dragMouse={x:e.touches[0].clientX-r.left,y:e.touches[0].clientY-r.top};},{passive:true});
-stage.addEventListener('touchend',()=>dragIdx=-1);
+// Pointer Events cover mouse, touch and pen; capture keeps the drag alive outside the stage.
+const localPos=e=>{const r=cvs.getBoundingClientRect();return{x:e.clientX-r.left,y:e.clientY-r.top};};
+stage.addEventListener('pointerdown',e=>{if(!e.isPrimary)return;dragMouse=localPos(e);dragIdx=getClosestVertex(dragMouse.x,dragMouse.y);try{stage.setPointerCapture(e.pointerId);}catch(_){}});
+stage.addEventListener('pointermove',e=>{if(dragIdx>=0&&e.isPrimary)dragMouse=localPos(e);});
+const endDrag=()=>dragIdx=-1;
+stage.addEventListener('pointerup',endDrag);
+stage.addEventListener('pointercancel',endDrag);
document.getElementById('res-sel').addEventListener('change',e=>{COLS=+e.target.value;ROWS=Math.round(COLS*.75);start();});
document.getElementById('grav-sl').addEventListener('input',e=>{GRAVITY=e.target.value/100;document.getElementById('grav-v').textContent=GRAVITY.toFixed(2);});
@@ -230,9 +233,10 @@ document.getElementById('cons-tog').addEventListener('change',e=>{SHOW_CONS=e.ta
document.getElementById('reset-btn').addEventListener('click',()=>initCloth());
document.getElementById('pause-btn').addEventListener('click',()=>{
paused=!paused;document.getElementById('pause-btn').textContent=paused?'▶ Resume':'⏸ Pause';
- if(!paused){lastT=performance.now();raf=requestAnimationFrame(loop);}
+ if(raf){cancelAnimationFrame(raf);raf=null;} // never leave two loops queued
+ if(paused)draw();else{lastT=performance.now();raf=requestAnimationFrame(loop);}
});
-window.addEventListener('resize',()=>{resize();initCloth();});
+window.addEventListener('resize',()=>{if(stage.clientWidth===W&&stage.clientHeight===H)return;resize();initCloth();});
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
</body>
diff --git a/animations/06-3d-advanced/flip-card-3d/index.html b/animations/06-3d-advanced/flip-card-3d/index.html
index 87dd7cbe..62bf2151 100644
--- a/animations/06-3d-advanced/flip-card-3d/index.html
+++ b/animations/06-3d-advanced/flip-card-3d/index.html
@@ -33,11 +33,13 @@
.stage-wrap{flex:1;min-width:0}
.stage{height:clamp(360px,52vh,560px);border:1px solid var(--ui-border);border-radius:8px;background:radial-gradient(120% 120% at 50% 0%,#141018,#08070a);display:flex;align-items:center;justify-content:center;padding:clamp(20px,4vw,48px);perspective:var(--perspective)}
/* Tilt wrapper carries the idle cursor-driven 3D tilt */
- .tilt{transform-style:preserve-3d;transition:transform 300ms ease}
+ .tilt{width:100%;display:flex;justify-content:center;transform-style:preserve-3d;transition:transform 300ms ease}
.tilt.tracking{transition:none}
/* Card — the flipping element */
.card{
- width:clamp(220px,60%,300px);aspect-ratio:5/7;position:relative;
+ /* capped by the stage height so the 5/7 card never spills past the stage border */
+ width:min(clamp(220px,60%,300px),calc((clamp(360px,52vh,560px) - 40px) * 5 / 7));
+ aspect-ratio:5/7;position:relative;
transform-style:preserve-3d;cursor:pointer;
transition:transform var(--flip-dur) cubic-bezier(.6,.02,.2,1);
will-change:transform
@@ -80,7 +82,7 @@
.seg button.on{border-color:var(--ui-accent);color:var(--ui-text)}
.div{height:1px;background:var(--ui-border)}
.flip-btn{min-height:44px;background:var(--ui-accent);border:0;border-radius:6px;color:#0b0b0d;font:inherit;font-weight:600;font-size:11px;cursor:pointer}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}}
+ @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}aside{width:100%}}
/* Tilt only on true hover-capable pointers */
@media(hover:hover){.tilt{will-change:transform}}
@media(hover:none){.tilt{transform:none!important}}
@@ -176,7 +178,8 @@ body{padding-top:46px}
function toggle(){setFlipped(!card.classList.contains('flipped'));}
// Trigger: click
- card.addEventListener('click',()=>{if(trigger==='click')toggle();});
+ // Hover trigger has no hover on touch devices, so a tap flips there instead
+ card.addEventListener('click',()=>{if(trigger==='click'||!canHover.matches)toggle();});
document.getElementById('flip-btn').addEventListener('click',toggle);
// Keyboard — flip is reachable and operable without a pointer
card.addEventListener('keydown',e=>{
@@ -184,7 +187,7 @@ body{padding-top:46px}
});
// Trigger: hover (pointer-capable devices only)
card.addEventListener('pointerenter',e=>{if(trigger==='hover'&&e.pointerType!=='touch')setFlipped(true);});
- card.addEventListener('pointerleave',()=>{if(trigger==='hover')setFlipped(false);});
+ card.addEventListener('pointerleave',e=>{if(trigger==='hover'&&e.pointerType!=='touch')setFlipped(false);});
// Cursor-driven idle 3D tilt via Pointer Events
const reduce=matchMedia('(prefers-reduced-motion:reduce)');
diff --git a/animations/06-3d-advanced/fluid-simulation/index.html b/animations/06-3d-advanced/fluid-simulation/index.html
index 5c40ba4b..04cce1e4 100644
--- a/animations/06-3d-advanced/fluid-simulation/index.html
+++ b/animations/06-3d-advanced/fluid-simulation/index.html
@@ -30,7 +30,7 @@
header h1{font-family:var(--disp);font-weight:700;letter-spacing:-.01em;font-size:clamp(11px,1.8vw,15px)}
header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
.layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;overflow:hidden;position:relative}
+ .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;overflow:hidden;position:relative;touch-action:pan-y}
canvas{display:block;width:100%;height:100%}
.fps-badge{position:absolute;top:8px;right:8px;font-size:9px;color:rgba(255,255,255,.5);background:rgba(0,0,0,.4);padding:3px 8px;border-radius:4px;pointer-events:none}
.no-webgl{position:absolute;inset:0;display:none;align-items:center;justify-content:center;color:var(--ui-muted);font-size:12px;text-align:center;padding:24px}
@@ -43,11 +43,10 @@
.sv{width:40px;text-align:right;color:var(--ui-text)}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}
button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:380px}}
- @media(prefers-reduced-motion:reduce){canvas{display:none}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:380px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -163,8 +162,7 @@ function resize(){
}
function render(ts){
- if(paused){raf=null;return;}
- raf=requestAnimationFrame(render);
+ raf=paused?null:requestAnimationFrame(render);
const dt=ts-lastT;if(dt<16)return;
const realFps=Math.round(1000/(dt||16));fpsEl.textContent=realFps+' fps';lastT=ts;
const t=(ts-startT)/1000*SPD;
@@ -187,9 +185,13 @@ function hexToRgb(hex){return[parseInt(hex.slice(1,3),16)/255,parseInt(hex.slice
if(init()){
resize();startT=performance.now();lastT=startT;
- raf=requestAnimationFrame(render);
- stage.addEventListener('mousemove',e=>{const r=cvs.getBoundingClientRect();mouseX=(e.clientX-r.left)/r.width;mouseY=1-(e.clientY-r.top)/r.height;});
- stage.addEventListener('touchmove',e=>{const r=cvs.getBoundingClientRect();mouseX=(e.touches[0].clientX-r.left)/r.width;mouseY=1-(e.touches[0].clientY-r.top)/r.height;},{passive:true});
+ if(matchMedia('(prefers-reduced-motion:reduce)').matches){
+ // Draw one still frame, then hold: the blobs stay visible but do not move.
+ paused=true;render(startT+16);fpsEl.textContent='paused';
+ document.getElementById('pause-btn').textContent='▶ Resume';
+ }else raf=requestAnimationFrame(render);
+ // Shader uv.y is flipped to top-down, so the pointer y must be top-down too.
+ stage.addEventListener('pointermove',e=>{const r=cvs.getBoundingClientRect();mouseX=(e.clientX-r.left)/r.width;mouseY=(e.clientY-r.top)/r.height;});
window.addEventListener('resize',resize);
}
@@ -201,9 +203,14 @@ document.getElementById('color-pick').addEventListener('input',e=>{COLOR=hexToRg
document.getElementById('bg-pick').addEventListener('input',e=>{BG=hexToRgb(e.target.value);});
document.getElementById('mouse-tog').addEventListener('change',e=>{MOUSE_BALL=e.target.checked;});
document.getElementById('glow-tog').addEventListener('change',e=>{GLOW=e.target.checked;});
+// While paused, a control change still repaints one frame so the result is visible.
+document.querySelector('aside').addEventListener('input',()=>{if(paused&&gl)render(lastT+16);});
document.getElementById('pause-btn').addEventListener('click',()=>{
paused=!paused;document.getElementById('pause-btn').textContent=paused?'▶ Resume':'⏸ Pause';
- if(!paused&&gl){lastT=performance.now();raf=requestAnimationFrame(render);}
+ if(!gl)return;
+ cancelAnimationFrame(raf);raf=null;
+ if(paused)fpsEl.textContent='paused';
+ else{lastT=performance.now();raf=requestAnimationFrame(render);}
});
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/06-3d-advanced/glassmorphism-animated/index.html b/animations/06-3d-advanced/glassmorphism-animated/index.html
index 32a0a9f5..a922f895 100644
--- a/animations/06-3d-advanced/glassmorphism-animated/index.html
+++ b/animations/06-3d-advanced/glassmorphism-animated/index.html
@@ -61,12 +61,15 @@
animation:blur-breath 4s ease-in-out infinite
}
.glass-card.g3{
+ background:var(--tint);
backdrop-filter:blur(var(--blur)) saturate(1.8);
-webkit-backdrop-filter:blur(var(--blur)) saturate(1.8);
border:1px solid rgba(255,255,255,.18);
box-shadow:0 8px 32px rgba(0,0,0,.3),inset 0 1px 0 rgba(255,255,255,.2);
animation:tint-cycle 8s linear infinite
}
+ /* !important so the perf toggle also beats the blur-breath keyframes on card 2 */
+ .stage.no-bf .glass-card{backdrop-filter:none!important;-webkit-backdrop-filter:none!important}
@keyframes blur-breath{
0%,100%{backdrop-filter:blur(8px) saturate(1.8);-webkit-backdrop-filter:blur(8px) saturate(1.8)}
50%{backdrop-filter:blur(20px) saturate(2);-webkit-backdrop-filter:blur(20px) saturate(2)}
@@ -90,8 +93,8 @@
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
.kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
.kv .v{color:var(--ui-text)}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:460px}}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}
+ @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:460px}.blob{filter:blur(36px)}}
@media(prefers-reduced-motion:reduce){.blob,.glass-card.g2,.glass-card.g3{animation:none!important}}
</style>
<style id="ah-inject">
@@ -157,14 +160,6 @@ body{padding-top:46px}
</aside>
</div>
<script>
- const cards=[...document.querySelectorAll('.glass-card')];
- function applyGlass(blur,op){
- cards.forEach(c=>{
- const perf=document.getElementById('perf-tog').checked;
- c.style.backdropFilter=perf?'none':`blur(${blur}px) saturate(1.8)`;
- c.style.webkitBackdropFilter=c.style.backdropFilter;
- });
- }
document.getElementById('blur-sl').addEventListener('input',e=>{
document.getElementById('blur-v').textContent=e.target.value+'px';
document.documentElement.style.setProperty('--blur',e.target.value+'px');
@@ -184,19 +179,17 @@ body{padding-top:46px}
const b=parseInt(e.target.value.slice(5,7),16);
document.documentElement.style.setProperty('--tint',`rgba(${r},${g},${b},var(--glass-op))`);
});
+ /* 'none' (not 'paused') so the card falls back to the slider/picker values while off */
document.getElementById('blur-tog').addEventListener('change',e=>{
- document.querySelector('.g2').style.animationPlayState=e.target.checked?'running':'paused';
+ document.querySelector('.g2').style.animation=e.target.checked?'':'none';
});
document.getElementById('tint-tog').addEventListener('change',e=>{
- document.querySelector('.g3').style.animationPlayState=e.target.checked?'running':'paused';
+ document.querySelector('.g3').style.animation=e.target.checked?'':'none';
});
document.getElementById('perf-tog').addEventListener('change',e=>{
const v=e.target.checked;
document.getElementById('perf-v').textContent=v?'Disabled (compare)':'Active';
- cards.forEach(c=>{
- c.style.backdropFilter=v?'none':'';
- c.style.webkitBackdropFilter=v?'none':'';
- });
+ document.getElementById('stage').classList.toggle('no-bf',v);
});
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/06-3d-advanced/gpgpu-particle-system/index.html b/animations/06-3d-advanced/gpgpu-particle-system/index.html
index d65cc4c0..d174ba6b 100644
--- a/animations/06-3d-advanced/gpgpu-particle-system/index.html
+++ b/animations/06-3d-advanced/gpgpu-particle-system/index.html
@@ -49,8 +49,7 @@
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:380px}}
- @media(prefers-reduced-motion:reduce){canvas{display:none}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:380px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -173,13 +172,17 @@ void main(){
const RENDER_FS=`#version 300 es
precision mediump float;in vec4 vCol;out vec4 fragColor;
void main(){fragColor=vCol;}`;
+// Trails: a translucent full-screen quad fades the previous frame instead of clearing it
+const FADE_FS=`#version 300 es
+precision mediump float;out vec4 fragColor;
+void main(){fragColor=vec4(.024,.039,.063,.12);}`;
const stage=document.getElementById('stage'),cvs=document.getElementById('cvs');
const fpsEl=document.getElementById('fps'),countBadge=document.getElementById('count-badge');
const behavBadge=document.getElementById('behavior-badge'),texSizeEl=document.getElementById('tex-size');
const noWgl2=document.getElementById('no-wgl2');
const BEHAV_NAMES=['Flow Field','Vortex','Attractor','Orbit'];
-let W,H,gl,physicsProg,renderProg,fbo0,fbo1,tex0,tex1,raf=null;
+let W,H,gl,physicsProg,renderProg,fadeProg,qBuf,fbo0,fbo1,tex0,tex1,raf=null;
let paused=false,lastT=0,startT=0,TEX_N=256,BEHAVIOR=0,SPD=0.6,COLOR_MODE=0,TRAILS=false;
let idxBuf=null,particleCount=0;
@@ -202,6 +205,7 @@ function initTex(n){
gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);
return t;
}
+ if(tex0){gl.deleteTexture(tex0);gl.deleteTexture(tex1);gl.deleteFramebuffer(fbo0);gl.deleteFramebuffer(fbo1);}
tex0=makeTex(data);tex1=makeTex(null);
function makeFbo(t){const f=gl.createFramebuffer();gl.bindFramebuffer(gl.FRAMEBUFFER,f);gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,t,0);return f;}
fbo0=makeFbo(tex0);fbo1=makeFbo(tex1);
@@ -216,14 +220,16 @@ function initTex(n){
}
function init(){
- gl=cvs.getContext('webgl2');
- if(!gl){noWgl2.style.display='flex';return false;}
+ // preserveDrawingBuffer keeps last frame for trails; alpha:false avoids premultiplied-alpha artifacts
+ gl=cvs.getContext('webgl2',{preserveDrawingBuffer:true,alpha:false});
+ // Rendering into RGBA32F framebuffers requires EXT_color_buffer_float in WebGL2
+ if(!gl||!gl.getExtension('EXT_color_buffer_float')){noWgl2.style.display='flex';return false;}
physicsProg=mkProg(PHYSICS_VS,PHYSICS_FS);
renderProg=mkProg(RENDER_VS,RENDER_FS);
- // Quad for physics pass
- const qBuf=gl.createBuffer();gl.bindBuffer(gl.ARRAY_BUFFER,qBuf);
+ fadeProg=mkProg(PHYSICS_VS,FADE_FS);
+ // Full-screen quad shared by the physics pass and the trail fade
+ qBuf=gl.createBuffer();gl.bindBuffer(gl.ARRAY_BUFFER,qBuf);
gl.bufferData(gl.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),gl.STATIC_DRAW);
- gl.bindVertexArray(null);
initTex(TEX_N);
return true;
}
@@ -241,9 +247,8 @@ function render(ts){
gl.useProgram(physicsProg);
gl.bindFramebuffer(gl.FRAMEBUFFER,fbo1);
gl.viewport(0,0,TEX_N,TEX_N);
- // Bind quad
- const quad=gl.createBuffer();gl.bindBuffer(gl.ARRAY_BUFFER,quad);
- gl.bufferData(gl.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),gl.DYNAMIC_DRAW);
+ gl.disable(gl.BLEND);
+ gl.bindBuffer(gl.ARRAY_BUFFER,qBuf);
const pa=gl.getAttribLocation(physicsProg,'a');gl.enableVertexAttribArray(pa);gl.vertexAttribPointer(pa,2,gl.FLOAT,false,0,0);
gl.activeTexture(gl.TEXTURE0);gl.bindTexture(gl.TEXTURE_2D,tex0);
gl.uniform1i(gl.getUniformLocation(physicsProg,'uPos'),0);
@@ -251,7 +256,6 @@ function render(ts){
gl.uniform1f(gl.getUniformLocation(physicsProg,'uSpd'),SPD);
gl.uniform1i(gl.getUniformLocation(physicsProg,'uBehavior'),BEHAVIOR);
gl.drawArrays(gl.TRIANGLE_STRIP,0,4);
- gl.deleteBuffer(quad);
// Swap textures
[tex0,tex1]=[tex1,tex0];[fbo0,fbo1]=[fbo1,fbo0];
@@ -259,8 +263,12 @@ function render(ts){
// ── Render pass (draw points) ──
gl.bindFramebuffer(gl.FRAMEBUFFER,null);
gl.viewport(0,0,W,H);
- if(TRAILS){gl.enable(gl.BLEND);gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA);gl.clearColor(0.024,0.039,0.063,0.1);gl.clear(gl.COLOR_BUFFER_BIT);}
- else{gl.clearColor(0.024,0.039,0.063,1);gl.clear(gl.COLOR_BUFFER_BIT);}
+ if(TRAILS){// fade the previous frame instead of clearing it
+ gl.enable(gl.BLEND);gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA);
+ gl.useProgram(fadeProg);gl.bindBuffer(gl.ARRAY_BUFFER,qBuf);
+ const fa=gl.getAttribLocation(fadeProg,'a');gl.enableVertexAttribArray(fa);gl.vertexAttribPointer(fa,2,gl.FLOAT,false,0,0);
+ gl.drawArrays(gl.TRIANGLE_STRIP,0,4);
+ }else{gl.clearColor(0.024,0.039,0.063,1);gl.clear(gl.COLOR_BUFFER_BIT);}
gl.enable(gl.BLEND);gl.blendFunc(gl.SRC_ALPHA,gl.ONE);
gl.useProgram(renderProg);
gl.bindBuffer(gl.ARRAY_BUFFER,idxBuf);
@@ -274,10 +282,14 @@ function render(ts){
gl.disable(gl.BLEND);
}
+const pauseBtn=document.getElementById('pause-btn');
if(init()){
resize();startT=performance.now();lastT=startT;
- raf=requestAnimationFrame(render);
window.addEventListener('resize',resize);
+ if(matchMedia('(prefers-reduced-motion: reduce)').matches){
+ // Reduced motion: draw one static frame, leave the loop stopped (user can opt in via Resume)
+ render(startT+16);cancelAnimationFrame(raf);raf=null;paused=true;pauseBtn.textContent='▶ Resume';
+ }else raf=requestAnimationFrame(render);
}
document.getElementById('count-sel').addEventListener('change',e=>{TEX_N=+e.target.value;if(gl)initTex(TEX_N);});
@@ -285,8 +297,9 @@ document.getElementById('behav-sel').addEventListener('change',e=>{BEHAVIOR=+e.t
document.getElementById('spd-sl').addEventListener('input',e=>{SPD=e.target.value/10;document.getElementById('spd-v').textContent=SPD.toFixed(1);});
document.getElementById('col-sel').addEventListener('change',e=>{COLOR_MODE=+e.target.value;});
document.getElementById('trail-tog').addEventListener('change',e=>{TRAILS=e.target.checked;});
-document.getElementById('pause-btn').addEventListener('click',()=>{
- paused=!paused;document.getElementById('pause-btn').textContent=paused?'▶ Resume':'⏸ Pause';
+pauseBtn.addEventListener('click',()=>{
+ paused=!paused;pauseBtn.textContent=paused?'▶ Resume':'⏸ Pause';
+ if(raf!==null){cancelAnimationFrame(raf);raf=null;}// never stack a second loop
if(!paused&&gl){lastT=performance.now();raf=requestAnimationFrame(render);}
});
</script>
diff --git a/animations/06-3d-advanced/image-distortion-hover/index.html b/animations/06-3d-advanced/image-distortion-hover/index.html
index 9ba7c0a6..82344177 100644
--- a/animations/06-3d-advanced/image-distortion-hover/index.html
+++ b/animations/06-3d-advanced/image-distortion-hover/index.html
@@ -31,7 +31,7 @@
header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
.layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
.stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;overflow:hidden;position:relative}
- canvas{display:block;width:100%;height:100%}
+ canvas{display:block;width:100%;height:100%;touch-action:none}
.fps-badge{position:absolute;top:8px;right:8px;font-size:9px;color:rgba(255,255,255,.5);background:rgba(0,0,0,.4);padding:3px 8px;border-radius:4px;pointer-events:none}
.src-panel{position:absolute;bottom:0;left:0;right:0;background:rgba(11,11,13,.92);border-top:1px solid var(--ui-border);padding:12px;font-size:9px;color:var(--ui-muted);font-family:var(--mono);line-height:1.5;max-height:180px;overflow-y:auto;display:none;white-space:pre-wrap}
aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
@@ -44,10 +44,9 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:380px}}
- @media(prefers-reduced-motion:reduce){canvas{display:none}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:380px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -117,7 +116,7 @@ void main(){
vec2 dir=uv-muv;dir.x*=ar;
float dist=length(dir);
float r=uRad;
- float falloff=smoothstep(r,0.,dist);
+ float falloff=1.-smoothstep(0.,r,dist);
vec2 duv=uv;
float str=uStr*.005;
if(uType==0){
@@ -130,7 +129,7 @@ void main(){
vec2 off=vec2(sin(dist*15.+uPhase)*cos(uv.y*10.+uPhase*.8),cos(dist*15.-uPhase)*sin(uv.x*10.+uPhase*.6));
duv+=off*falloff*str*.6;
}else{
- float px=mix(.002,.04,1.-falloff*(uStr/20.));
+ float px=mix(.002,.04,falloff*(uStr/20.));
duv=floor(uv/px)*px;
}
gl_FragColor=vec4(pat(duv),1.);
@@ -140,7 +139,7 @@ const stage=document.getElementById('stage'),cvs=document.getElementById('cvs');
const fpsEl=document.getElementById('fps'),srcPanel=document.getElementById('src-panel');
let W,H,gl,prog,raf=null,paused=false,lastT=0,startT=0;
let TYPE=0,STR=8,RAD=0.25,DECAY=0.5,ANIMATE=true;
-let mouseX=-999,mouseY=-999,phase=0;
+let mouseX=-999,mouseY=-999,phase=0,amp=0,active=false,t0=0;
function init(){
gl=cvs.getContext('webgl');if(!gl)return false;
@@ -163,29 +162,39 @@ function render(ts){
raf=requestAnimationFrame(render);
const dt=ts-lastT;if(dt<16)return;
fpsEl.textContent=Math.round(1000/(dt||16))+' fps';lastT=ts;
- phase+=(ts-startT)/1000*.003;startT=ts;
+ phase+=(ts-startT)*.003;if(phase>Math.PI*10)phase-=Math.PI*10;startT=ts;
+ if(!active){amp*=Math.max(0,1-DECAY*.016);if(amp<.005){amp=0;mouseX=mouseY=-999;}}
+ draw(ts);
+}
+function draw(ts){
gl.useProgram(prog);
gl.uniform2f(u('uRes'),W,H);
gl.uniform2f(u('uMouse'),mouseX,mouseY);
- gl.uniform1f(u('uT'),(ts-startT)/1000);
- gl.uniform1f(u('uStr'),STR);
+ gl.uniform1f(u('uT'),(ts-t0)/1000);
+ gl.uniform1f(u('uStr'),STR*amp);
gl.uniform1f(u('uRad'),RAD);
- gl.uniform1f(u('uPhase'),phase*10);
+ gl.uniform1f(u('uPhase'),phase);
gl.uniform1i(u('uType'),TYPE);
gl.uniform1i(u('uAnimate'),ANIMATE?1:0);
gl.drawArrays(gl.TRIANGLE_STRIP,0,4);
- if(mouseX<0)phase*=Math.max(0,1-DECAY*.016);
}
+srcPanel.textContent=FS;
if(init()){
- resize();startT=performance.now();lastT=startT;
- raf=requestAnimationFrame(render);
- stage.addEventListener('mousemove',e=>{const r=cvs.getBoundingClientRect();mouseX=e.clientX-r.left;mouseY=e.clientY-r.top;phase=0;});
- stage.addEventListener('mouseleave',()=>{mouseX=mouseY=-999;});
- stage.addEventListener('touchmove',e=>{const r=cvs.getBoundingClientRect();mouseX=e.touches[0].clientX-r.left;mouseY=e.touches[0].clientY-r.top;},{passive:true});
+ resize();t0=startT=performance.now();lastT=startT;
+ if(matchMedia('(prefers-reduced-motion:reduce)').matches){
+ // Reduced motion: show one static frame; the user can opt in with Resume.
+ paused=true;document.getElementById('pause-btn').textContent='▶ Resume';fpsEl.textContent='paused';draw(t0);
+ }else raf=requestAnimationFrame(render);
+ const track=e=>{const r=cvs.getBoundingClientRect();mouseX=e.clientX-r.left;mouseY=e.clientY-r.top;active=true;amp=1;};
+ const release=()=>{active=false;};
+ stage.addEventListener('pointermove',track);
+ stage.addEventListener('pointerdown',track);
+ stage.addEventListener('pointerleave',release);
+ stage.addEventListener('pointerup',e=>{if(e.pointerType!=='mouse')release();});
+ stage.addEventListener('pointercancel',release);
window.addEventListener('resize',resize);
- srcPanel.textContent=FS;
-}
+}else fpsEl.textContent='WebGL unavailable';
document.getElementById('type-sel').addEventListener('change',e=>{TYPE=+e.target.value;});
document.getElementById('str-sl').addEventListener('input',e=>{STR=+e.target.value;document.getElementById('str-v').textContent=STR;});
@@ -195,7 +204,8 @@ document.getElementById('ripple-tog').addEventListener('change',e=>{ANIMATE=e.ta
document.getElementById('src-tog').addEventListener('change',e=>{srcPanel.style.display=e.target.checked?'block':'none';});
document.getElementById('pause-btn').addEventListener('click',()=>{
paused=!paused;document.getElementById('pause-btn').textContent=paused?'▶ Resume':'⏸ Pause';
- if(!paused&&gl){lastT=performance.now();startT=lastT;raf=requestAnimationFrame(render);}
+ if(paused){if(raf)cancelAnimationFrame(raf);raf=null;}
+ else if(gl&&!raf){lastT=performance.now();startT=lastT;raf=requestAnimationFrame(render);}
});
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/06-3d-advanced/morphing-blob/index.html b/animations/06-3d-advanced/morphing-blob/index.html
index 45c89a88..961651c5 100644
--- a/animations/06-3d-advanced/morphing-blob/index.html
+++ b/animations/06-3d-advanced/morphing-blob/index.html
@@ -43,7 +43,7 @@
.div{height:1px;background:var(--ui-border)}
.kv{display:flex;justify-content:space-between;font-size:10px;color:var(--muted)}
.kv .v{color:var(--text)}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:56vh}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:0 0 auto}aside{width:100%}:root{--stage-h:56vh}}
@media(prefers-reduced-motion:reduce){.tip{display:none}}
</style>
<style id="ah-inject">
@@ -93,7 +93,7 @@ body{padding-top:46px}
<aside>
<p class="note">No shaders and no libraries — the whole liquid effect is one SVG filter over plain moving circles. Blur softens, the color-matrix re-hardens the edge, and the metaballs appear to melt together.</p>
<div class="lbl">Gooeyness (blur)</div>
- <div class="row"><input type="range" id="goo" min="4" max="22" step="1" value="10"><span class="sv" id="gooV">10</span></div>
+ <div class="row"><input type="range" id="gooRange" min="4" max="22" step="1" value="10"><span class="sv" id="gooV">10</span></div>
<div class="lbl">Blob count</div>
<div class="row"><input type="range" id="count" min="3" max="10" step="1" value="6"><span class="sv" id="countV">6</span></div>
<div class="lbl">Drift speed</div>
@@ -108,7 +108,7 @@ body{padding-top:46px}
<script>
const NS='http://www.w3.org/2000/svg';
const group=document.getElementById('blobs'),blur=document.getElementById('blur'),tip=document.getElementById('tip');
-const gooEl=document.getElementById('goo'),gooV=document.getElementById('gooV');
+const gooEl=document.getElementById('gooRange'),gooV=document.getElementById('gooV');
const countEl=document.getElementById('count'),countV=document.getElementById('countV');
const speedEl=document.getElementById('speed'),speedV=document.getElementById('speedV');
const stage=document.getElementById('stage');
diff --git a/animations/06-3d-advanced/noise-based-motion/index.html b/animations/06-3d-advanced/noise-based-motion/index.html
index 577b5c4b..2df4b24b 100644
--- a/animations/06-3d-advanced/noise-based-motion/index.html
+++ b/animations/06-3d-advanced/noise-based-motion/index.html
@@ -41,11 +41,10 @@
.sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
.sv{width:40px;text-align:right;color:var(--ui-text)}
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}
button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:380px}}
- @media(prefers-reduced-motion:reduce){canvas{display:none}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:380px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -177,11 +176,15 @@ function loop(ts){
const dt=ts-lastT;if(dt<16){return;}
const realFps=Math.round(1000/(dt||16));fpsEl.textContent=realFps+' fps';
lastT=ts;t+=SPD*.01;
- ctx.clearRect(0,0,W,H);
- if(MODE==='grid')drawGrid();else drawBlob();
+ frame();
}
+function frame(){ctx.clearRect(0,0,W,H);if(MODE==='grid')drawGrid();else drawBlob();}
-resize();raf=requestAnimationFrame(loop);
+resize();
+if(matchMedia('(prefers-reduced-motion: reduce)').matches){
+ // Reduced motion: show a single static frame, user can opt in via Resume
+ paused=true;document.getElementById('pause-btn').textContent='▶ Resume';frame();
+}else{raf=requestAnimationFrame(loop);}
document.getElementById('mode-sel').addEventListener('change',e=>MODE=e.target.value);
document.getElementById('scale-sl').addEventListener('input',e=>{SCALE=e.target.value/1000;document.getElementById('scale-v').textContent=(SCALE).toFixed(3);});
@@ -192,9 +195,12 @@ document.getElementById('verts-sl').addEventListener('input',e=>{VERTS=+e.target
document.getElementById('color-pick').addEventListener('input',e=>COLOR=e.target.value);
document.getElementById('pause-btn').addEventListener('click',()=>{
paused=!paused;document.getElementById('pause-btn').textContent=paused?'▶ Resume':'⏸ Pause';
- if(!paused){lastT=performance.now();raf=requestAnimationFrame(loop);}
+ if(paused){cancelAnimationFrame(raf);raf=null;}
+ else if(!raf){lastT=performance.now();raf=requestAnimationFrame(loop);}
});
-window.addEventListener('resize',()=>{resize();});
+// While paused, keep the static frame in sync with the controls
+document.querySelector('aside').addEventListener('input',()=>{if(paused)frame();});
+window.addEventListener('resize',()=>{resize();if(paused)frame();});
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
</body>
diff --git a/animations/06-3d-advanced/parallax-3d-tilt/index.html b/animations/06-3d-advanced/parallax-3d-tilt/index.html
index d385145a..ad435cfd 100644
--- a/animations/06-3d-advanced/parallax-3d-tilt/index.html
+++ b/animations/06-3d-advanced/parallax-3d-tilt/index.html
@@ -41,7 +41,7 @@
transform-style:preserve-3d;
transform:perspective(var(--perspective)) rotateX(0deg) rotateY(0deg) scale(1);
transition:transform var(--reset-dur) ease,box-shadow var(--reset-dur) ease;
- cursor:pointer;
+ cursor:pointer;touch-action:none;
will-change:transform
}
.tilt-card.active{transition:none}
@@ -139,9 +139,8 @@ body{padding-top:46px}
function onMove(e){
const r=card.getBoundingClientRect();
- const src=e.touches?e.touches[0]:e;
- const x=(src.clientX-r.left)/r.width-.5; // -0.5 to 0.5
- const y=(src.clientY-r.top)/r.height-.5;
+ const x=(e.clientX-r.left)/r.width-.5; // -0.5 to 0.5
+ const y=(e.clientY-r.top)/r.height-.5;
const inv=invert?-1:1;
const rx=(-y*maxTilt*inv).toFixed(1);
const ry=(x*maxTilt*inv).toFixed(1);
@@ -171,10 +170,9 @@ body{padding-top:46px}
readout.textContent='rotX: 0° rotY: 0°';
}
- card.addEventListener('mousemove',onMove);
- card.addEventListener('mouseleave',onLeave);
- card.addEventListener('touchmove',e=>{e.preventDefault();onMove(e);},{passive:false});
- card.addEventListener('touchend',onLeave);
+ card.addEventListener('pointermove',onMove);
+ card.addEventListener('pointerleave',onLeave);
+ card.addEventListener('pointercancel',onLeave);
document.getElementById('tilt-sl').addEventListener('input',e=>{maxTilt=+e.target.value;document.getElementById('tilt-v').textContent=maxTilt+'°'});
document.getElementById('persp-sl').addEventListener('input',e=>{
diff --git a/animations/06-3d-advanced/ray-marching-sdf/index.html b/animations/06-3d-advanced/ray-marching-sdf/index.html
index c6359e88..c6dd5b60 100644
--- a/animations/06-3d-advanced/ray-marching-sdf/index.html
+++ b/animations/06-3d-advanced/ray-marching-sdf/index.html
@@ -47,8 +47,7 @@
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:380px}}
- @media(prefers-reduced-motion:reduce){canvas{display:none}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:380px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -75,7 +74,7 @@ body{padding-top:46px}
<canvas id="cvs"></canvas>
<div class="hud">
<div class="badge" id="fps">— fps</div>
- <div class="badge" id="scene-badge">Scene 1</div>
+ <div class="badge" id="scene-badge">Scene 1: Blend</div>
</div>
<div class="src-panel" id="src-panel"></div>
</div>
@@ -184,8 +183,8 @@ void main(){
const stage=document.getElementById('stage'),cvs=document.getElementById('cvs');
const fpsEl=document.getElementById('fps'),sceneBadge=document.getElementById('scene-badge');
-const srcPanel=document.getElementById('src-panel');
-let W,H,gl,prog,raf=null,paused=false,lastT=0,startT=0;
+const srcPanel=document.getElementById('src-panel'),pauseBtn=document.getElementById('pause-btn');
+let W,H,gl,prog,raf=null,paused=false,lastT=0,startT=0,curT=0;
let SCENE=0,CAM_SPD=0.6,MAX_STEPS=48,AO=true,SHADOW=false,DEBUG=false;
const SCENE_NAMES=['Blend','Boolean','Repetition'];
@@ -203,7 +202,7 @@ function init(){
srcPanel.textContent=FS;
return true;
}
-function resize(){W=cvs.width=stage.clientWidth;H=cvs.height=stage.clientHeight;if(gl)gl.viewport(0,0,W,H);}
+function resize(){W=cvs.width=stage.clientWidth;H=cvs.height=stage.clientHeight;if(gl){gl.viewport(0,0,W,H);if(paused)draw(curT);}}
function u(n){return gl.getUniformLocation(prog,n);}
function render(ts){
@@ -211,7 +210,10 @@ function render(ts){
raf=requestAnimationFrame(render);
const dt=ts-lastT;if(dt<16)return;
fpsEl.textContent=Math.round(1000/(dt||16))+' fps';lastT=ts;
- const t=(ts-startT)/1000;
+ draw((ts-startT)/1000);
+}
+function draw(t){
+ curT=t;
gl.useProgram(prog);
gl.uniform2f(u('uRes'),W,H);
gl.uniform1f(u('uT'),t);
@@ -224,10 +226,17 @@ function render(ts){
gl.drawArrays(gl.TRIANGLE_STRIP,0,4);
}
+// Resume from the time we paused at so the camera does not jump; never stack a second loop.
+function start(){lastT=performance.now();startT=lastT-curT*1000;if(raf===null)raf=requestAnimationFrame(render);}
+function stop(){if(raf!==null)cancelAnimationFrame(raf);raf=null;}
+
if(init()){
- resize();startT=performance.now();lastT=startT;
- raf=requestAnimationFrame(render);
+ resize();
+ if(matchMedia('(prefers-reduced-motion:reduce)').matches){paused=true;pauseBtn.textContent='▶ Resume';draw(0);}
+ else start();
window.addEventListener('resize',resize);
+ cvs.addEventListener('webglcontextlost',e=>{e.preventDefault();stop();});
+ cvs.addEventListener('webglcontextrestored',()=>{init();resize();if(paused)draw(curT);else start();});
}
document.getElementById('scene-sel').addEventListener('change',e=>{SCENE=+e.target.value;sceneBadge.textContent='Scene '+(SCENE+1)+': '+SCENE_NAMES[SCENE];});
@@ -237,9 +246,10 @@ document.getElementById('ao-tog').addEventListener('change',e=>{AO=e.target.chec
document.getElementById('shadow-tog').addEventListener('change',e=>{SHADOW=e.target.checked;});
document.getElementById('debug-tog').addEventListener('change',e=>{DEBUG=e.target.checked;});
document.getElementById('src-tog').addEventListener('change',e=>{srcPanel.style.display=e.target.checked?'block':'none';});
-document.getElementById('pause-btn').addEventListener('click',()=>{
- paused=!paused;document.getElementById('pause-btn').textContent=paused?'▶ Resume':'⏸ Pause';
- if(!paused&&gl){lastT=performance.now();startT=lastT;raf=requestAnimationFrame(render);}
+pauseBtn.addEventListener('click',()=>{
+ paused=!paused;pauseBtn.textContent=paused?'▶ Resume':'⏸ Pause';
+ if(!gl)return;
+ if(paused)stop();else start();
});
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/06-3d-advanced/scroll-driven-3d-rotation/index.html b/animations/06-3d-advanced/scroll-driven-3d-rotation/index.html
index 4eb06259..9068a659 100644
--- a/animations/06-3d-advanced/scroll-driven-3d-rotation/index.html
+++ b/animations/06-3d-advanced/scroll-driven-3d-rotation/index.html
@@ -68,9 +68,9 @@
.sv{width:40px;text-align:right;color:var(--ui-text)}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;min-height:44px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:480px}.info-panel{width:120px;padding:12px}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}.info-panel{width:120px;padding:12px}}
@media(prefers-reduced-motion:reduce){.obj-wrap{transition:none!important}.prog-fill{transition:none!important}}
</style>
<style id="ah-inject">
@@ -138,7 +138,7 @@ body{padding-top:46px}
<div class="lbl">Scroll Progress</div>
<div class="sr" style="pointer-events:none"><input type="range" id="prog-sl" min="0" max="100" value="0" step="1" style="pointer-events:none"><span class="sv" id="prog-sl-v">0%</span></div>
<div class="lbl">Rotation Multiplier</div>
- <div class="sr"><input type="range" id="mult-sl" min="5" max="30" value="10" step="1"><span class="sv" id="mult-v">1×</span></div>
+ <div class="sr"><input type="range" id="mult-sl" min="5" max="30" value="10" step="1"><span class="sv" id="mult-v">1.0×</span></div>
<label class="tog"><input type="checkbox" id="smooth-tog" checked><span>Smooth scrub (lerp)</span></label>
<div class="div"></div>
<div class="kv"><span>Rotation X</span><span class="v" id="rx-v">0°</span></div>
@@ -156,10 +156,13 @@ const progVal=document.getElementById('prog-val');
const stageName=document.getElementById('stage-name');
const stageDesc=document.getElementById('stage-desc');
const dots=[...document.querySelectorAll('.chapter-dot')];
-let currRx=0,currRy=0,currSc=1,raf=null,mult=10;
+let currRx=0,currRy=0,currSc=1,tgtRx=0,tgtRy=0,tgtSc=1,raf=null,mult=10;
+const reduceMotion=matchMedia('(prefers-reduced-motion: reduce)');
+// Each chapter is the end state the object reaches by the end of that quarter of scroll
+const START={rx:0,ry:0,sc:1};
const CHAPTERS=[
- {name:'Orbit Y',desc:'Rotating 90° around the Y axis.',rx:0,ry:0,sc:1},
+ {name:'Orbit Y',desc:'Rotating 90° around the Y axis.',rx:0,ry:90,sc:1},
{name:'Tilt X',desc:'Tilting 30° forward on the X axis.',rx:-30,ry:90,sc:1},
{name:'Scale Up',desc:'Growing 1.4× while tilted.',rx:-30,ry:90,sc:1.4},
{name:'Back Face',desc:'Completing −180° Y rotation to show the back.',rx:0,ry:-180,sc:1},
@@ -167,19 +170,31 @@ const CHAPTERS=[
function lerp(a,b,t){return a+(b-a)*t}
-function applyRotation(p){
- const ch=Math.floor(p*4);const cp=Math.min(ch,3);const t=p*4-cp;
- const c0=CHAPTERS[Math.max(cp-1,0)];const c1=CHAPTERS[Math.min(cp,3)];
- let rx=lerp(c0.rx,c1.rx,t),ry=lerp(c0.ry,c1.ry,t),sc=lerp(c0.sc,c1.sc,t);
- const smooth=document.getElementById('smooth-tog').checked;
- if(smooth){currRx=lerp(currRx,rx,.1);currRy=lerp(currRy,ry,.1);currSc=lerp(currSc,sc,.1);}
- else{currRx=rx;currRy=ry;currSc=sc;}
+function render(){
objWrap.style.transform=`rotateX(${currRx.toFixed(1)}deg) rotateY(${currRy.toFixed(1)}deg) scale(${currSc.toFixed(3)})`;
document.getElementById('rx-v').textContent=currRx.toFixed(0)+'°';
document.getElementById('ry-v').textContent=currRy.toFixed(0)+'°';
document.getElementById('sc-v').textContent=currSc.toFixed(2);
+}
+
+// Smooth scrub: keep easing toward the target each frame until it settles, then stop the loop
+function tick(){
+ raf=null;
+ currRx=lerp(currRx,tgtRx,.1);currRy=lerp(currRy,tgtRy,.1);currSc=lerp(currSc,tgtSc,.1);
+ if(Math.abs(tgtRx-currRx)>.05||Math.abs(tgtRy-currRy)>.05||Math.abs(tgtSc-currSc)>.001){render();raf=requestAnimationFrame(tick);}
+ else{currRx=tgtRx;currRy=tgtRy;currSc=tgtSc;render();}
+}
+
+function applyRotation(p){
+ const cp=Math.min(Math.floor(p*4),3);const t=p*4-cp;
+ const c0=cp>0?CHAPTERS[cp-1]:START;const c1=CHAPTERS[cp];
+ const k=mult/10;
+ tgtRx=lerp(c0.rx,c1.rx,t)*k;tgtRy=lerp(c0.ry,c1.ry,t)*k;tgtSc=lerp(c0.sc,c1.sc,t);
+ const smooth=document.getElementById('smooth-tog').checked&&!reduceMotion.matches;
+ if(smooth){if(!raf)raf=requestAnimationFrame(tick);}
+ else{if(raf){cancelAnimationFrame(raf);raf=null;}currRx=tgtRx;currRy=tgtRy;currSc=tgtSc;render();}
- const chIdx=Math.min(Math.floor(p*4),3);
+ const chIdx=cp;
dots.forEach((d,i)=>d.classList.toggle('active',i===chIdx));
stageName.textContent=CHAPTERS[chIdx].name;
stageDesc.textContent=CHAPTERS[chIdx].desc;
@@ -198,10 +213,12 @@ function onScroll(){
stageEl.addEventListener('scroll',onScroll,{passive:true});
document.getElementById('mult-sl').addEventListener('input',e=>{
- mult=+e.target.value;document.getElementById('mult-v').textContent=(mult/10).toFixed(1)+'×';
+ mult=+e.target.value;document.getElementById('mult-v').textContent=(mult/10).toFixed(1)+'×';onScroll();
});
+document.getElementById('smooth-tog').addEventListener('change',onScroll);
document.getElementById('reset-btn').addEventListener('click',()=>{
- stageEl.scrollTop=0;currRx=currRy=0;currSc=1;applyRotation(0);
+ if(raf){cancelAnimationFrame(raf);raf=null;}
+ stageEl.scrollTop=0;currRx=currRy=0;currSc=1;applyRotation(0);render();
});
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/06-3d-advanced/svg-path-animation/index.html b/animations/06-3d-advanced/svg-path-animation/index.html
index 5f32804f..44824cf2 100644
--- a/animations/06-3d-advanced/svg-path-animation/index.html
+++ b/animations/06-3d-advanced/svg-path-animation/index.html
@@ -39,7 +39,7 @@
}
.draw-path.fill-done{fill:rgba(88,166,255,.15);transition:fill .4s ease}
.preset-tabs{display:flex;gap:6px}
- .ptab{background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:10px;padding:6px 14px;border-radius:4px;cursor:pointer;min-height:36px;transition:border-color .15s,color .15s}
+ .ptab{background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:10px;padding:6px 14px;border-radius:4px;cursor:pointer;min-height:44px;transition:border-color .15s,color .15s}
.ptab.active{border-color:var(--ui-accent);color:var(--ui-accent)}
.svg-label{font-size:10px;color:var(--ui-muted);letter-spacing:2px;text-transform:uppercase}
/* Panel */
@@ -55,8 +55,8 @@
select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}
+ button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%;min-height:44px}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
@media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{height:auto;min-height:420px}}
@media(prefers-reduced-motion:reduce){.draw-path{stroke-dashoffset:0!important;transition:none!important}}
@@ -141,7 +141,7 @@ const PRESETS=[
}
];
-let current=0,loopTimer=null,animating=false;
+let current=0,loopTimer=null,animating=false,run=0;
const svg=document.getElementById('svg-stage');
const group=document.getElementById('drawing-group');
const tabs=document.getElementById('tabs');
@@ -176,6 +176,7 @@ function buildPaths(){
function animate(paths){
if(animating)return;animating=true;
+ const id=++run; // timers from an older run bail out once a newer run starts
const dur=getDur();const ease=getEase();const rev=getReverse();
const totalLen=paths.reduce((a,p)=>a+p.getTotalLength(),0);
pathLenEl.textContent=Math.round(totalLen)+'px';
@@ -187,11 +188,14 @@ function animate(paths){
path.style.transition='none';
const delay=i*(dur*0.3);
setTimeout(()=>{
+ if(id!==run)return;
+ path.getBoundingClientRect(); // flush the hidden state so the transition has a start value
path.style.transition=`stroke-dashoffset ${dur}ms ${ease}`;
path.style.strokeDashoffset=rev?len:0;
const isLast=i===paths.length-1;
if(isLast){
setTimeout(()=>{
+ if(id!==run)return;
if(getFill())paths.forEach(p=>p.classList.add('fill-done'));
animating=false;
if(document.getElementById('loop-tog').checked){
@@ -207,7 +211,7 @@ function replay(){
clearTimeout(loopTimer);animating=false;
const paths=buildPaths();
paths.forEach(p=>p.classList.remove('fill-done'));
- setTimeout(()=>animate(paths),60);
+ animate(paths);
}
document.getElementById('replay-btn').addEventListener('click',replay);
diff --git a/animations/06-3d-advanced/volumetric-smoke/index.html b/animations/06-3d-advanced/volumetric-smoke/index.html
index c3775fc3..196bbb7c 100644
--- a/animations/06-3d-advanced/volumetric-smoke/index.html
+++ b/animations/06-3d-advanced/volumetric-smoke/index.html
@@ -44,11 +44,11 @@
.sv{width:40px;text-align:right;color:var(--ui-text)}
.tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- input[type=color]{border:none;background:none;width:44px;height:30px;cursor:pointer;border-radius:4px;padding:0}
+ input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0}
button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:380px}}
- @media(prefers-reduced-motion:reduce){canvas{display:none}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{width:100%;flex:none}aside{width:100%}:root{--stage-h:380px}}
+ /* prefers-reduced-motion: the script renders one static frame and starts paused */
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -169,7 +169,7 @@ void main(){
const stage=document.getElementById('stage'),cvs=document.getElementById('cvs');
const fpsEl=document.getElementById('fps'),stepsBadge=document.getElementById('steps-badge');
const srcPanel=document.getElementById('src-panel');
-let W,H,gl,prog,raf=null,paused=false,lastT=0,startT=0;
+let W,H,gl,prog,raf=null,paused=false,lastT=0,startT=0,pausedAt=0,curT=2;
let DENS=0.7,SPD=0.6,STEPS=32,WIND=true,DITHER=true;
let SMOKE=[154/255,180/255,216/255],BG=[3/255,8/255,16/255];
@@ -184,15 +184,20 @@ function init(){
const a=gl.getAttribLocation(prog,'a');gl.enableVertexAttribArray(a);gl.vertexAttribPointer(a,2,gl.FLOAT,false,0,0);
srcPanel.textContent=FS;return true;
}
-function resize(){W=cvs.width=stage.clientWidth;H=cvs.height=stage.clientHeight;if(gl)gl.viewport(0,0,W,H);}
+function resize(){W=cvs.width=stage.clientWidth;H=cvs.height=stage.clientHeight;if(gl){gl.viewport(0,0,W,H);refresh();}}
function u(n){return gl.getUniformLocation(prog,n);}
+// Resizing clears the canvas and control changes need a frame: redraw while paused
+function refresh(){if(paused&&gl)draw(curT);}
function render(ts){
if(paused){raf=null;return;}
raf=requestAnimationFrame(render);
const dt=ts-lastT;if(dt<16)return;
fpsEl.textContent=Math.round(1000/(dt||16))+' fps';lastT=ts;
- const t=(ts-startT)/1000;
+ draw((ts-startT)/1000);
+}
+function draw(t){
+ curT=t;
gl.useProgram(prog);
gl.uniform2f(u('uRes'),W,H);gl.uniform1f(u('uT'),t);
gl.uniform1f(u('uDens'),DENS);gl.uniform1f(u('uSpd'),SPD);
@@ -202,19 +207,28 @@ function render(ts){
gl.drawArrays(gl.TRIANGLE_STRIP,0,4);
}
-if(init()){resize();startT=performance.now();lastT=startT;raf=requestAnimationFrame(render);window.addEventListener('resize',resize);}
+const pauseBtn=document.getElementById('pause-btn');
+if(init()){
+ resize();startT=performance.now();lastT=startT;window.addEventListener('resize',resize);
+ if(matchMedia('(prefers-reduced-motion: reduce)').matches){
+ paused=true;pausedAt=startT;pauseBtn.textContent='▶ Resume';fpsEl.textContent='static';draw(curT);
+ }else raf=requestAnimationFrame(render);
+}else fpsEl.textContent='WebGL unavailable';
-document.getElementById('dens-sl').addEventListener('input',e=>{DENS=e.target.value/10;document.getElementById('dens-v').textContent=DENS.toFixed(1);});
+document.getElementById('dens-sl').addEventListener('input',e=>{DENS=e.target.value/10;document.getElementById('dens-v').textContent=DENS.toFixed(1);refresh();});
document.getElementById('spd-sl').addEventListener('input',e=>{SPD=e.target.value/10;document.getElementById('spd-v').textContent=SPD.toFixed(1);});
-document.getElementById('steps-sl').addEventListener('input',e=>{STEPS=+e.target.value;document.getElementById('steps-v').textContent=STEPS;stepsBadge.textContent=STEPS+' steps';});
-document.getElementById('smoke-pick').addEventListener('input',e=>{SMOKE=h2r(e.target.value);});
-document.getElementById('bg-pick').addEventListener('input',e=>{BG=h2r(e.target.value);});
-document.getElementById('wind-tog').addEventListener('change',e=>{WIND=e.target.checked;});
-document.getElementById('dither-tog').addEventListener('change',e=>{DITHER=e.target.checked;});
+document.getElementById('steps-sl').addEventListener('input',e=>{STEPS=+e.target.value;document.getElementById('steps-v').textContent=STEPS;stepsBadge.textContent=STEPS+' steps';refresh();});
+document.getElementById('smoke-pick').addEventListener('input',e=>{SMOKE=h2r(e.target.value);refresh();});
+document.getElementById('bg-pick').addEventListener('input',e=>{BG=h2r(e.target.value);refresh();});
+document.getElementById('wind-tog').addEventListener('change',e=>{WIND=e.target.checked;refresh();});
+document.getElementById('dither-tog').addEventListener('change',e=>{DITHER=e.target.checked;refresh();});
document.getElementById('src-tog').addEventListener('change',e=>{srcPanel.style.display=e.target.checked?'block':'none';});
-document.getElementById('pause-btn').addEventListener('click',()=>{
- paused=!paused;document.getElementById('pause-btn').textContent=paused?'▶ Resume':'⏸ Pause';
- if(!paused&&gl){lastT=performance.now();raf=requestAnimationFrame(render);}
+pauseBtn.addEventListener('click',()=>{
+ paused=!paused;pauseBtn.textContent=paused?'▶ Resume':'⏸ Pause';
+ cancelAnimationFrame(raf);raf=null; // never leave a second loop queued
+ const now=performance.now();
+ if(paused){pausedAt=now;return;}
+ if(gl){startT+=now-pausedAt;lastT=now;raf=requestAnimationFrame(render);}
});
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
diff --git a/animations/06-3d-advanced/webgl-shader-animation/index.html b/animations/06-3d-advanced/webgl-shader-animation/index.html
index 0c3c564a..b84b2204 100644
--- a/animations/06-3d-advanced/webgl-shader-animation/index.html
+++ b/animations/06-3d-advanced/webgl-shader-animation/index.html
@@ -30,7 +30,7 @@
header h1{font-family:var(--disp);font-weight:700;letter-spacing:-.01em;font-size:clamp(11px,1.8vw,15px)}
header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
.layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;overflow:hidden;position:relative}
+ .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;overflow:hidden;position:relative;touch-action:pan-y}
canvas{display:block;width:100%;height:100%}
.overlay{position:absolute;top:8px;left:8px;right:8px;display:flex;justify-content:space-between;align-items:flex-start;pointer-events:none}
.fps-badge{font-size:9px;color:rgba(255,255,255,.5);background:rgba(0,0,0,.4);padding:3px 8px;border-radius:4px}
@@ -48,8 +48,7 @@
.tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}
@media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:380px}}
- @media(prefers-reduced-motion:reduce){canvas{display:none}}
+ @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:380px}}
</style>
<style id="ah-inject">
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
@@ -162,7 +161,8 @@ void main(){
const stage=document.getElementById('stage');const cvs=document.getElementById('cvs');
const fpsEl=document.getElementById('fps');const shaderName=document.getElementById('shader-name');
const srcPanel=document.getElementById('src-panel');
-let W,H,gl,prog=null,raf=null,paused=false,lastT=0,startT=0;
+const pauseBtn=document.getElementById('pause-btn');
+let W,H,gl,prog=null,raf=null,paused=false,lastT=0,T=0;
let PRESET=0,SPD=1,HUE=0,MOUSE_UV=[.5,.5],MOUSE_ON=false;
function mkProg(fs){
@@ -182,6 +182,7 @@ function init(){
function switchShader(idx){
PRESET=idx;
+ if(!gl)return;
if(prog)gl.deleteProgram(prog);
prog=mkProg(SHADERS[idx].src);
const a=gl.getAttribLocation(prog,'a');
@@ -190,40 +191,53 @@ function switchShader(idx){
if(document.getElementById('src-tog').checked)srcPanel.textContent=SHADERS[idx].src;
}
-function resize(){W=cvs.width=stage.clientWidth;H=cvs.height=stage.clientHeight;if(gl)gl.viewport(0,0,W,H);}
+function resize(){W=cvs.width=stage.clientWidth;H=cvs.height=stage.clientHeight;if(gl){gl.viewport(0,0,W,H);still();}}
-function render(ts){
- if(paused){raf=null;return;}
- raf=requestAnimationFrame(render);
- const dt=ts-lastT;if(dt<16)return;
- fpsEl.textContent=Math.round(1000/(dt||16))+' fps';lastT=ts;
- const t=(ts-startT)/1000*SPD;
+function draw(){
gl.useProgram(prog);
const u=n=>gl.getUniformLocation(prog,n);
- gl.uniform2f(u('R'),W,H);gl.uniform1f(u('T'),t);gl.uniform1f(u('H'),HUE);
+ gl.uniform2f(u('R'),W,H);gl.uniform1f(u('T'),T);gl.uniform1f(u('H'),HUE);
if(MOUSE_ON){gl.uniform2f(u('M'),MOUSE_UV[0],MOUSE_UV[1]);gl.uniform1i(u('uMouse'),1);}
else gl.uniform1i(u('uMouse'),0);
gl.drawArrays(gl.TRIANGLE_STRIP,0,4);
}
+// Redraw the held frame while paused so controls still take effect.
+function still(){if(paused&&prog)draw();}
+
+function render(ts){
+ if(paused){raf=null;return;}
+ raf=requestAnimationFrame(render);
+ const dt=ts-lastT;if(dt<16)return;
+ fpsEl.textContent=Math.round(1000/(dt||16))+' fps';lastT=ts;
+ T+=Math.min(dt,100)/1000*SPD;
+ draw();
+}
+
+function setPaused(p){
+ paused=p;pauseBtn.textContent=paused?'▶ Resume':'⏸ Pause';
+ if(paused){cancelAnimationFrame(raf);raf=null;still();}
+ else if(gl&&raf===null){lastT=performance.now();raf=requestAnimationFrame(render);}
+}
if(init()){
- resize();startT=lastT=performance.now();raf=requestAnimationFrame(render);
- stage.addEventListener('mousemove',e=>{const r=cvs.getBoundingClientRect();MOUSE_UV=[(e.clientX-r.left)/r.width,(e.clientY-r.top)/r.height];});
+ resize();
+ if(matchMedia('(prefers-reduced-motion:reduce)').matches)setPaused(true);
+ else{lastT=performance.now();raf=requestAnimationFrame(render);}
+ stage.addEventListener('pointermove',e=>{const r=cvs.getBoundingClientRect();MOUSE_UV=[(e.clientX-r.left)/r.width,(e.clientY-r.top)/r.height];still();});
window.addEventListener('resize',resize);
+}else{
+ cvs.style.display='none';fpsEl.textContent='WebGL is not available in this browser';
}
-document.getElementById('preset-sel').addEventListener('change',e=>{switchShader(+e.target.value);});
+document.getElementById('preset-sel').addEventListener('change',e=>{switchShader(+e.target.value);still();});
document.getElementById('spd-sl').addEventListener('input',e=>{SPD=e.target.value/10;document.getElementById('spd-v').textContent=SPD.toFixed(1);});
-document.getElementById('hue-sl').addEventListener('input',e=>{HUE=+e.target.value;document.getElementById('hue-v').textContent=HUE+'°';});
-document.getElementById('mouse-tog').addEventListener('change',e=>{MOUSE_ON=e.target.checked;});
+document.getElementById('hue-sl').addEventListener('input',e=>{HUE=+e.target.value;document.getElementById('hue-v').textContent=HUE+'°';still();});
+document.getElementById('mouse-tog').addEventListener('change',e=>{MOUSE_ON=e.target.checked;still();});
document.getElementById('src-tog').addEventListener('change',e=>{
srcPanel.style.display=e.target.checked?'block':'none';
if(e.target.checked)srcPanel.textContent=SHADERS[PRESET].src;
});
-document.getElementById('pause-btn').addEventListener('click',()=>{
- paused=!paused;document.getElementById('pause-btn').textContent=paused?'▶ Resume':'⏸ Pause';
- if(!paused&&gl){lastT=performance.now();raf=requestAnimationFrame(render);}
-});
+pauseBtn.addEventListener('click',()=>setPaused(!paused));
</script>
<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
</body>