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 the 14 Text & Typography demos (section 5)

matinf024cc42ed96
diff --git a/animations/05-text-typography/enter-exit-typography/index.html b/animations/05-text-typography/enter-exit-typography/index.html
index 3a88ffa5..e465bab7 100644
--- a/animations/05-text-typography/enter-exit-typography/index.html
+++ b/animations/05-text-typography/enter-exit-typography/index.html
@@ -197,6 +197,10 @@ function start(){
}
document.getElementById('replay-btn').addEventListener('click',start);
+// re-enabling Loop after the sequence finished restarts it (sibling demos behave this way)
+document.getElementById('loop-tog').addEventListener('change',e=>{
+ if(e.target.checked&&phaseKv.textContent==='Done')start();
+});
document.getElementById('enter-sl').addEventListener('input',e=>{
document.getElementById('enter-v').textContent=e.target.value+'ms';
document.documentElement.style.setProperty('--enter-dur',e.target.value+'ms');
diff --git a/animations/05-text-typography/glitch-text/index.html b/animations/05-text-typography/glitch-text/index.html
index ec831aec..4eada469 100644
--- a/animations/05-text-typography/glitch-text/index.html
+++ b/animations/05-text-typography/glitch-text/index.html
@@ -47,7 +47,8 @@
animation:slice var(--speed) infinite linear alternate-reverse}
.glitch::after{color:#2dffe6;text-shadow:var(--offset) 0 #2dffe6;left:var(--offset);
animation:slice2 var(--speed) infinite linear alternate-reverse}
- /* clip-path slices are re-randomized from JS via --a../--b.. custom props */
+ .glitch::before,.glitch::after{animation-delay:var(--phase,0s)}
+ /* JS reshuffles the slice phase by restarting the clones with a random negative delay (--phase) */
@keyframes slice{
0%{clip-path:inset(20% 0 60% 0)}20%{clip-path:inset(70% 0 5% 0)}
40%{clip-path:inset(10% 0 80% 0)}60%{clip-path:inset(45% 0 35% 0)}
@@ -122,13 +123,13 @@ body{padding-top:46px}
const glitch=document.getElementById('glitch');
const stage=document.getElementById('stage');
const root=document.documentElement;
-const reduce=matchMedia('(prefers-reduced-motion:reduce)').matches;
-let intensity=0.6,jitterTimer=null;
+const reduceMQ=matchMedia('(prefers-reduced-motion:reduce)');
+let intensity=0.6,jitterTimer=null,dur=2.4;
// Re-randomize the clip-path keyframes so each burst of slices differs.
function rand(max){return Math.floor(Math.random()*max)}
function reslice(){
- if(reduce)return;
+ if(reduceMQ.matches){glitch.style.transform='';jitterTimer=null;return}
// amplitude of the tear scales with intensity: low intensity = thin, rare bands
const spread=Math.round(intensity*40);
const jitter=(intensity*6).toFixed(1);
@@ -137,8 +138,9 @@ function reslice(){
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
+ // occasionally restart the clone animations at a random point on their timeline
if(Math.random()<intensity){
+ glitch.style.setProperty('--phase',(-Math.random()*dur).toFixed(2)+'s');
glitch.classList.add('reset');void glitch.offsetWidth;glitch.classList.remove('reset');
}
}else{
@@ -154,7 +156,7 @@ function fit(){
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;
+ const t=(e.target.value.trim()||'GLITCH');glitch.textContent=t;glitch.dataset.text=t;
glitch.style.setProperty('--n',t.length); // longer words shrink so they stay inside the stage
fit();
});
@@ -166,7 +168,7 @@ document.getElementById('off-sl').addEventListener('input',e=>{
});
document.getElementById('spd-sl').addEventListener('input',e=>{
// higher slider = faster = shorter duration (invert)
- const dur=(14-+e.target.value)*0.4;
+ dur=(14-+e.target.value)*0.4;
root.style.setProperty('--speed',dur.toFixed(1)+'s');
document.getElementById('spd-sv').textContent=dur.toFixed(1)+'s';
});
@@ -182,7 +184,8 @@ document.getElementById('hover-ck').addEventListener('change',e=>{
stage.addEventListener('pointerdown',e=>{
if(e.pointerType!=='mouse'&&stage.classList.contains('paused'))stage.classList.toggle('active');
});
-if(!reduce)reslice();
+if(!reduceMQ.matches)reslice();
+reduceMQ.addEventListener('change',e=>{if(!e.matches&&jitterTimer===null)reslice()});
</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/05-text-typography/kinetic-typography/index.html b/animations/05-text-typography/kinetic-typography/index.html
index ae4263d6..ddeb9bfb 100644
--- a/animations/05-text-typography/kinetic-typography/index.html
+++ b/animations/05-text-typography/kinetic-typography/index.html
@@ -57,7 +57,7 @@
@keyframes kExitRight{from{opacity:1;transform:translateX(0)}to{opacity:0;transform:translateX(80px)}}
/* Beat markers */
.beat-bar{position:absolute;bottom:0;left:0;right:0;height:3px;background:var(--ui-border)}
- .beat-fill{height:100%;background:var(--ui-accent);width:0%;transition:width 100ms linear}
+ .beat-fill{height:100%;background:var(--ui-accent);transform-origin:left;transform:scaleX(0);transition:transform 100ms linear}
/* Phrase counter */
.phrase-counter{position:absolute;top:14px;right:14px;font-size:10px;color:var(--ui-muted);letter-spacing:1px}
/* Panel */
@@ -75,7 +75,7 @@
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;align-items:stretch}aside{width:100%}:root{--stage-h:420px}.stage{flex:none}}
- @media(prefers-reduced-motion:reduce){.kw{animation:none!important;opacity:1!important;transform:none!important}}
+ @media(prefers-reduced-motion:reduce){.kw{animation:none!important;opacity:1!important;transform:none!important;clip-path:none!important}.beat-fill{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}
@@ -142,7 +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;
- beatFill.style.width=((i+1)/PHRASES.length*100).toFixed(0)+'%';
+ beatFill.style.transform='scaleX('+((i+1)/PHRASES.length)+')';
requestAnimationFrame(()=>{
w.classList.add(p.enter);
if(p.sub)phraseEl.querySelectorAll('.sub').forEach(s=>{s.style.animationDelay='200ms';s.classList.add(p.enter);});
@@ -155,7 +155,7 @@ function exitPhrase(i,done){
w.style.animationDelay='';w.classList.remove(p.enter);w.classList.add(p.exit);
});
// Every pending timeout in the chain is stored in `timer` so Play/Restart can cancel it.
- timer=setTimeout(done,ms(450));
+ timer=setTimeout(done,ms(520));
}
function run(){
@@ -170,7 +170,7 @@ function run(){
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%';timer=setTimeout(run,ms(800));}
+ if(document.getElementById('loop-tog').checked){beatFill.style.transform='scaleX(0)';timer=setTimeout(run,ms(800));}
}
});
},ms(500+hold));
@@ -179,7 +179,7 @@ function run(){
}
document.getElementById('play-btn').addEventListener('click',()=>{
- clearTimeout(timer);running=false;beatFill.style.width='0%';
+ clearTimeout(timer);running=false;beatFill.style.transform='scaleX(0)';
timer=setTimeout(run,50);
});
document.getElementById('spd-sl').addEventListener('input',e=>{
diff --git a/animations/05-text-typography/marquee-ticker/index.html b/animations/05-text-typography/marquee-ticker/index.html
index baee21c3..d184d151 100644
--- a/animations/05-text-typography/marquee-ticker/index.html
+++ b/animations/05-text-typography/marquee-ticker/index.html
@@ -142,18 +142,29 @@ body{padding-top:46px}
}
function getSep(){return document.getElementById('sep-sel').value}
- function updateSpeed(track){
+ // Fraction of the loop a track has completed (0-1), so a duration change or rebuild can resume in place
+ function progressOf(track){
+ const an=track&&track.getAnimations()[0];const d=track&&track.durMs;
+ return an&&d&&an.currentTime!=null?(an.currentTime%d)/d:0;
+ }
+ function updateSpeed(track,frac){
const spd=+document.getElementById('spd-sl').value;
const oneCopy=track.scrollWidth/2; // -50% travel distance
- track.style.animationDuration=(oneCopy/spd).toFixed(2)+'s';
+ if(frac==null)frac=progressOf(track);
+ track.durMs=Math.round(oneCopy/spd*1000);
+ track.style.animationDuration=track.durMs+'ms';
+ // Changing duration keeps elapsed time, not progress: re-seat the animation so the text does not jump
+ const an=track.getAnimations()[0];if(an)an.currentTime=frac*track.durMs;
}
function rebuild(){
const text=getContent();const sep=getSep();
+ const frac=progressOf(stage.querySelector('.marq-track'));
stage.innerHTML='';
buildRow(text,sep,false,'');
buildRow(text,sep,true,'accent');
buildRow(text+' '+sep+' '+text,sep,false,'');
+ document.querySelectorAll('.marq-track').forEach(t=>updateSpeed(t,frac));
}
function refreshSpeeds(){
diff --git a/animations/05-text-typography/outline-to-fill/index.html b/animations/05-text-typography/outline-to-fill/index.html
index 4f6aac23..9a7a66da 100644
--- a/animations/05-text-typography/outline-to-fill/index.html
+++ b/animations/05-text-typography/outline-to-fill/index.html
@@ -215,7 +215,7 @@ body{padding-top:46px}
fillLayer.classList.add('filled');
strokeWrap.classList.add('filled');
}));
- if(document.getElementById('loop-tog').checked){
+ if(document.getElementById('loop-tog').checked&&!matchMedia('(prefers-reduced-motion: reduce)').matches){
loopTimer=setTimeout(()=>{reset();loopTimer=setTimeout(play,300);},dur+1400);
}
}
diff --git a/animations/05-text-typography/rotate-word-carousel/index.html b/animations/05-text-typography/rotate-word-carousel/index.html
index 4f914b71..504b6e5b 100644
--- a/animations/05-text-typography/rotate-word-carousel/index.html
+++ b/animations/05-text-typography/rotate-word-carousel/index.html
@@ -180,11 +180,12 @@ Startups</textarea>
rotWord.classList.add(enterMap[dir]);
void rotWord.offsetWidth;
rotWord.style.transition='';
- requestAnimationFrame(()=>requestAnimationFrame(()=>{
+ // timer (not rAF) so the loop keeps advancing when the tab is throttled
+ setTimeout(()=>{
if(id!==run)return;
rotWord.classList.remove(...enterClasses);
setTimeout(()=>{if(id===run)done()},getDur()+50);
- }));
+ },20);
},getDur()+30);
}
diff --git a/animations/05-text-typography/scramble-text/index.html b/animations/05-text-typography/scramble-text/index.html
index 5e38241d..1159aa00 100644
--- a/animations/05-text-typography/scramble-text/index.html
+++ b/animations/05-text-typography/scramble-text/index.html
@@ -56,7 +56,7 @@
@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){.scramble-text .char{transition:none!important;color:#fff!important}}
</style>
<style id="ah-inject">
@@ -120,13 +120,15 @@ const CHARSETS={
matrix:'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン',
all:'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*<>{}[]'
};
-let cycleTimer=null,running=false,timers=[];
+let cycleTimer=null,cycleFn=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');
const cycleCt=document.getElementById('cycle-ct');
+const charsetSel=document.getElementById('charset-sel');
+const loopTog=document.getElementById('loop-tog');
function randChar(charset){return charset[Math.floor(Math.random()*charset.length)]}
@@ -136,7 +138,7 @@ function scramble(){
timers.forEach(clearTimeout);timers=[];
running=true;
const text=document.getElementById('text-inp').value.toUpperCase();
- const charset=CHARSETS[document.getElementById('charset-sel').value];
+ const charset=CHARSETS[charsetSel.value];
const cycleMs=+document.getElementById('cyc-sl').value;
const settleMs=+document.getElementById('settle-sl').value;
const reduce=reduceMotion.matches;
@@ -171,15 +173,15 @@ function scramble(){
if(lockedCount===total){
clearInterval(cycleTimer);cycleTimer=null;
running=false;out.setAttribute('aria-label',text);
- if(document.getElementById('loop-tog').checked)later(scramble,1200);
+ // Re-check the toggle when the timer fires so unchecking mid-gap cancels the next run
+ if(loopTog.checked)later(()=>{if(loopTog.checked)scramble()},1200);
}
},settleMs*i+settleMs);
});
- // Cycle random chars on unlocked positions
- cycleTimer=setInterval(()=>{
- spans.forEach((s,i)=>{if(s&&!locked[i])s.textContent=randChar(charset);});
- },cycleMs);
+ // Cycle random chars on unlocked positions; charset is read per tick so the select applies live
+ cycleFn=()=>{const cs=CHARSETS[charsetSel.value];spans.forEach((s,i)=>{if(s&&!locked[i])s.textContent=randChar(cs);});};
+ cycleTimer=setInterval(cycleFn,cycleMs);
const totalTime=settleMs*total+settleMs;
const thisTimer=cycleTimer;
@@ -189,8 +191,14 @@ function 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('cyc-sl').addEventListener('input',e=>{
+ document.getElementById('cyc-v').textContent=e.target.value+'ms';
+ // Apply live: swap the running interval for one at the new rate
+ if(running&&cycleTimer){clearInterval(cycleTimer);cycleTimer=setInterval(cycleFn,+e.target.value);cycleCt.textContent=e.target.value+'ms';}
+});
document.getElementById('settle-sl').addEventListener('input',e=>document.getElementById('settle-v').textContent=e.target.value+'ms');
+document.getElementById('settle-sl').addEventListener('change',scramble);
+loopTog.addEventListener('change',()=>{if(loopTog.checked&&!running)scramble();});
document.getElementById('text-inp').addEventListener('keydown',e=>{if(e.key==='Enter')scramble()});
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 40a47305..0f3c5bf6 100644
--- a/animations/05-text-typography/text-clip-path-reveal/index.html
+++ b/animations/05-text-typography/text-clip-path-reveal/index.html
@@ -118,7 +118,8 @@ Always.</textarea>
</div>
<script>
const headline=document.getElementById('headline');
- let loopTimer=null;
+ let loopTimer=null,lineTimers=[];
+ const reducedMotion=matchMedia('(prefers-reduced-motion: reduce)');
function getDir(){return document.getElementById('dir-sel').value}
function getDirClass(dir){
@@ -144,6 +145,7 @@ Always.</textarea>
function reveal(){
if(loopTimer){clearTimeout(loopTimer);loopTimer=null}
+ lineTimers.forEach(clearTimeout);lineTimers=[];
const dur=+document.getElementById('dur-sl').value;
const stag=+document.getElementById('stag-sl').value;
document.documentElement.style.setProperty('--line-dur',dur+'ms');
@@ -151,11 +153,12 @@ Always.</textarea>
document.documentElement.style.setProperty('--ease',document.getElementById('ease-sel').value);
const lines=buildLines();
+ void headline.offsetWidth; // flush styles so the new spans have a clip-path start value to transition from
lines.forEach((span,i)=>{
- setTimeout(()=>{span.classList.add('revealed');},50+stag*i);
+ lineTimers.push(setTimeout(()=>{span.classList.add('revealed');},50+stag*i));
});
- if(document.getElementById('loop-tog').checked){
+ if(document.getElementById('loop-tog').checked&&!reducedMotion.matches){
const total=50+stag*(lines.length-1)+dur+1200;
loopTimer=setTimeout(reveal,total);
}
diff --git a/animations/05-text-typography/text-gradient-animation/index.html b/animations/05-text-typography/text-gradient-animation/index.html
index 91235e20..606498c9 100644
--- a/animations/05-text-typography/text-gradient-animation/index.html
+++ b/animations/05-text-typography/text-gradient-animation/index.html
@@ -50,9 +50,10 @@
}
/* Linear */
.grad-linear{background-image:linear-gradient(90deg,#58a6ff,#56d364,#d2a8ff,#ffa657,#58a6ff)}
- /* Conic */
+ /* Conic — a registered <angle> property lets the gradient's "from" angle interpolate, so it truly rotates */
+ @property --ang{syntax:'<angle>';inherits:false;initial-value:0deg}
.grad-conic{
- background-image:conic-gradient(from 0deg,#58a6ff,#56d364,#d2a8ff,#ffa657,#58a6ff);
+ background-image:conic-gradient(from var(--ang),#58a6ff,#56d364,#d2a8ff,#ffa657,#58a6ff);
animation:grad-spin var(--grad-dur) linear infinite;
background-size:200% 200%;background-position:50% 50%
}
@@ -61,7 +62,7 @@
/* Custom two-color */
.grad-custom{background-image:linear-gradient(90deg,var(--c1,#58a6ff),var(--c2,#d2a8ff),var(--c1,#58a6ff))}
@keyframes grad-flow{from{background-position:0% 50%}to{background-position:300% 50%}}
- @keyframes grad-spin{from{background-position:0% 0%}to{background-position:100% 100%}}
+ @keyframes grad-spin{from{--ang:0deg}to{--ang:360deg}}
.grad-label{font-size:10px;letter-spacing:3px;text-transform:uppercase;color:var(--ui-muted)}
/* 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}
@@ -77,7 +78,7 @@
.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: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}}
+ @media(prefers-reduced-motion:reduce){.grad-text{animation:none!important}.grad-text:not(.grad-conic){background-position:0% 50%!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}
diff --git a/animations/05-text-typography/text-morphing/index.html b/animations/05-text-typography/text-morphing/index.html
index c0a14836..f6122926 100644
--- a/animations/05-text-typography/text-morphing/index.html
+++ b/animations/05-text-typography/text-morphing/index.html
@@ -78,7 +78,7 @@
:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
body{padding-top:46px}
.ah-bar{position:fixed;top:0;left:0;right:0;height:46px;z-index:2147483000;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 clamp(10px,3vw,18px);background:var(--ah-bg);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border-bottom:1px solid var(--ah-line);font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;box-sizing:border-box}
-.ah-bar a,.ah-bar button{color:var(--ah-muted);text-decoration:none;background:none;border:0;font:inherit;cursor:pointer;display:inline-flex;align-items:center;gap:6px;min-height:34px;padding:0 7px;border-radius:6px;transition:color .18s,background .18s;white-space:nowrap}
+.ah-bar a,.ah-bar button{color:var(--ah-muted);text-decoration:none;background:none;border:0;font:inherit;cursor:pointer;display:inline-flex;align-items:center;gap:6px;min-height:44px;padding:0 7px;border-radius:6px;transition:color .18s,background .18s;white-space:nowrap}
.ah-bar a:hover,.ah-bar button:hover{color:var(--ah-ink)}
.ah-home{color:var(--ah-ink);font-weight:600}
.ah-actions{display:flex;align-items:center;gap:2px}
@@ -129,7 +129,7 @@ SOUND</textarea>
</aside>
</div>
<script>
- let wordIdx=0,morphTimer=null,running=false,gen=0;
+ let wordIdx=0,morphTimer=null,running=false;
const wordEl=document.getElementById('current-word');
const dotsEl=document.getElementById('dots');
const curWordKv=document.getElementById('cur-word-kv');
@@ -178,7 +178,6 @@ SOUND</textarea>
});
const exitDur=dur+(stag*(fromChars.length-1));
- const myGen=gen;
morphTimer=setTimeout(()=>{
// Build new word off-screen
wordEl.innerHTML='';
@@ -189,19 +188,21 @@ SOUND</textarea>
if(stag>0)s.style.transitionDelay=(stag*i)+'ms';
s.textContent=c;wordEl.appendChild(s);toChars.push(s);
});
- // 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));
- morphTimer=setTimeout(done,enterDur+50);
- }));
+ // Animate in: force a style flush so the transition starts from the off-screen state
+ void wordEl.offsetWidth;
+ toChars.forEach(c=>c.classList.remove(enterDir));
+ const enterDur=dur+(stag*(toChars.length-1));
+ morphTimer=setTimeout(done,enterDur+50);
},exitDur+60);
}
function cycle(){
const words=getWords();
- if(words.length<2)return;
+ if(words.length<2){ // list edited down to one word mid-cycle: sync display, loop resumes on next edit
+ running=false;wordIdx=0;buildDots(words);
+ if(words[0]){showWord(words[0]);curWordKv.textContent=words[0]}else{wordEl.innerHTML='';curWordKv.textContent='—'}
+ 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
@@ -220,7 +221,7 @@ SOUND</textarea>
}
function start(){
- if(morphTimer)clearTimeout(morphTimer);running=false;wordIdx=0;gen++;
+ if(morphTimer)clearTimeout(morphTimer);running=false;wordIdx=0;
const words=getWords();
if(!words.length){wordEl.innerHTML='';dotsEl.innerHTML='';curWordKv.textContent='—';return}
buildDots(words);showWord(words[0]);curWordKv.textContent=words[0];
@@ -228,6 +229,7 @@ SOUND</textarea>
}
document.getElementById('restart-btn').addEventListener('click',start);
+ document.getElementById('words-inp').addEventListener('input',()=>{if(!running)start()});
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 c411f299..bd2ebbbd 100644
--- a/animations/05-text-typography/text-on-path/index.html
+++ b/animations/05-text-typography/text-on-path/index.html
@@ -52,6 +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(prefers-reduced-motion:reduce){.guide{transition:none}}
@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">
@@ -106,7 +107,7 @@ body{padding-top:46px}
const tp=document.getElementById('tp');
const curve=document.getElementById('curve');
const guide=document.getElementById('guide');
-const reduce=matchMedia('(prefers-reduced-motion:reduce)').matches;
+const reduce=matchMedia('(prefers-reduced-motion:reduce)');
const PATHS={
wave:'M20,180 C120,60 240,300 340,180 S560,60 620,180',
arc:'M20,300 Q320,20 620,300',
@@ -128,11 +129,13 @@ function fill(){
tp.textContent=s.repeat(Math.ceil(100/unit)+1);
}
function loop(){
+ if(reduce.matches){raf=null;return;}
offset=(offset+speed)%unit;
tp.setAttribute('startOffset',(offset-unit)+'%');
raf=requestAnimationFrame(loop);
}
-function start(){ if(reduce||raf)return; raf=requestAnimationFrame(loop); }
+function start(){ if(reduce.matches||raf)return; raf=requestAnimationFrame(loop); }
+reduce.addEventListener('change',start);
inp.addEventListener('input',fill);
document.getElementById('spd-sl').addEventListener('input',e=>{
diff --git a/animations/05-text-typography/typewriter-effect/index.html b/animations/05-text-typography/typewriter-effect/index.html
index e45f6b71..198cd5aa 100644
--- a/animations/05-text-typography/typewriter-effect/index.html
+++ b/animations/05-text-typography/typewriter-effect/index.html
@@ -184,8 +184,16 @@ body{padding-top:46px}
});
}
+ const reduceMotion=matchMedia('(prefers-reduced-motion: reduce)');
function start(){
const text=document.getElementById('text-inp').value;
+ if(reduceMotion.matches){
+ // No per-character loop: show the finished line at once.
+ if(timer)clearTimeout(timer);running=false;
+ typeOut.textContent=text;typeOut.appendChild(makeCursor());
+ statChars.textContent=text.length;statSpeed.textContent=getSpeed()+'ms';
+ return;
+ }
if(document.getElementById('delete-tog').checked){
deleteAndRetype(text);
}else{
diff --git a/animations/05-text-typography/variable-font-morph/index.html b/animations/05-text-typography/variable-font-morph/index.html
index 32121255..8a5620fc 100644
--- a/animations/05-text-typography/variable-font-morph/index.html
+++ b/animations/05-text-typography/variable-font-morph/index.html
@@ -137,6 +137,7 @@ const PRESETS=[
{wght:400,CASL:1,slnt:0},{wght:300,CASL:0,slnt:-15},{wght:1000,CASL:0,slnt:0}
];
let autoTimer=null,autoIdx=0;
+function stopAuto(){clearInterval(autoTimer);autoTimer=null;document.getElementById('auto-btn').textContent='▶ Auto-morph presets';}
function apply(wght,CASL,slnt){
document.documentElement.style.setProperty('--wght',wght);
@@ -154,18 +155,21 @@ function apply(wght,CASL,slnt){
}
document.getElementById('wght-sl').addEventListener('input',e=>{
+ stopAuto();
const v=+e.target.value;
document.getElementById('wght-sv').textContent=v;
document.getElementById('wght-v').textContent=v;
document.documentElement.style.setProperty('--wght',v);
});
document.getElementById('casl-sl').addEventListener('input',e=>{
+ stopAuto();
const v=e.target.value/100;
document.getElementById('casl-sv').textContent=v.toFixed(1);
document.getElementById('casl-v').textContent=v.toFixed(1);
document.documentElement.style.setProperty('--CASL',v);
});
document.getElementById('slnt-sl').addEventListener('input',e=>{
+ stopAuto();
const v=+e.target.value;
document.getElementById('slnt-sv').textContent=v+'°';
document.getElementById('slnt-v').textContent=v+'°';
@@ -176,12 +180,12 @@ document.getElementById('text-inp').addEventListener('input',e=>{
});
document.querySelectorAll('.preset-btn').forEach(btn=>{
btn.addEventListener('click',()=>{
- clearInterval(autoTimer);autoTimer=null;document.getElementById('auto-btn').textContent='▶ Auto-morph presets';
+ stopAuto();
apply(+btn.dataset.wght,+btn.dataset.casl*100,+btn.dataset.slnt);
});
});
document.getElementById('auto-btn').addEventListener('click',()=>{
- if(autoTimer){clearInterval(autoTimer);autoTimer=null;document.getElementById('auto-btn').textContent='▶ Auto-morph presets';return;}
+ if(autoTimer){stopAuto();return;}
document.getElementById('auto-btn').textContent='■ Stop';
autoIdx=0;
function step(){const p=PRESETS[autoIdx%PRESETS.length];apply(p.wght,p.CASL*100,p.slnt);autoIdx++;}
diff --git a/animations/05-text-typography/wavy-text/index.html b/animations/05-text-typography/wavy-text/index.html
index 260a9342..4ea48d19 100644
--- a/animations/05-text-typography/wavy-text/index.html
+++ b/animations/05-text-typography/wavy-text/index.html
@@ -37,7 +37,7 @@
line-height:1;letter-spacing:.01em;color:#fff;white-space:pre;-webkit-user-select:none;user-select:none}
/* each character is its own span, offset in the wave by --i * stagger */
.wave-text span{display:inline-block;will-change:transform;
- animation:bob var(--dur) ease-in-out infinite;
+ animation:bob var(--dur) ease-in-out infinite backwards;
animation-delay:calc(var(--i) * var(--stagger))}
@keyframes bob{
0%,100%{transform:translateY(calc(var(--amp) * .6))}
@@ -115,7 +115,7 @@ 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';
+ if(room>0&&wave.offsetWidth>room) wave.style.fontSize=parseFloat(getComputedStyle(wave).fontSize)*room/wave.offsetWidth+'px';
}
build('Wavy');
addEventListener('resize',fit);