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: stop Glitch's hover mode with a tap, and measure text after the font loads

matin45ff5ea20cb6
diff --git a/animations/05-text-typography/glitch-text/index.html b/animations/05-text-typography/glitch-text/index.html
index 3c7c4730..b6f83c9c 100644
--- a/animations/05-text-typography/glitch-text/index.html
+++ b/animations/05-text-typography/glitch-text/index.html
@@ -186,14 +186,16 @@
function rand(max){return Math.floor(Math.random()*max)}
// Runs on its own timer: nudges the word sideways and, by chance, restarts the color copies at a
- // random point so the tear never repeats. It always ends by scheduling its own next call, so only
- // one call is ever pending; hb:pause below clears that pending call before pausing or restarting it.
+ // random point so the tear never repeats. Except under reduced motion, where it stops, it ends by
+ // scheduling its own next call, so only one call is ever pending; hb:pause below clears that pending
+ // call before pausing or restarting it.
function reslice(){
if(reduceMQ.matches){glitch.style.transform='';jitterTimer=null;return}
const spread=Math.round(intensity*40);
const jitter=(intensity*6).toFixed(1);
- // in hover-only mode the jitter only runs while the stage is hovered / tapped active
- const live=!stage.classList.contains('hover-only')||stage.matches(':hover')||stage.classList.contains('active');
+ // in hover-only mode the jitter only runs while the stage is hovered / tapped active; a touch screen
+ // keeps :hover on the stage after a tap, so only a device that can hover counts as hovering
+ const live=!stage.classList.contains('hover-only')||(matchMedia('(hover:hover)').matches&&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)`;
@@ -234,6 +236,7 @@
});
addEventListener('resize',fit);
fit();
+ if(document.fonts)document.fonts.ready.then(fit); // the site font can still be loading when fit() first runs
hoverTog.addEventListener('change',()=>{
stage.classList.toggle('hover-only',hoverTog.checked);
diff --git a/animations/05-text-typography/marquee-ticker/index.html b/animations/05-text-typography/marquee-ticker/index.html
index 943e56a5..2c68d890 100644
--- a/animations/05-text-typography/marquee-ticker/index.html
+++ b/animations/05-text-typography/marquee-ticker/index.html
@@ -24,7 +24,7 @@
:root{--ui-accent:#ff6f8b;--marq-size:48px;--marq-gap:48px}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
.stage{display:flex;flex-direction:column;justify-content:center;background:#08080a}
- .marq-row{overflow:hidden;padding:16px 0;border-bottom:1px solid rgba(255,255,255,.09);position:relative}
+ .marq-row{overflow:hidden;padding:16px 0;border-bottom:1px solid rgba(255,255,255,.09)}
.marq-row:last-child{border-bottom:none}
.marq-row.accent{background:rgba(255,111,139,.05)}
.marq-track{display:flex;width:max-content;white-space:nowrap;animation:marqL linear infinite}
@@ -35,7 +35,7 @@
@keyframes marqR{from{transform:translateX(-50%)}to{transform:translateX(0)}}
.marq-item{font-size:var(--marq-size);font-weight:700;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}
+ .sep{color:var(--ui-accent);font-size:.6em;opacity:.7}
</style>
<link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
<script src="../../../assets/js/demo-page.js?v=3" defer></script>
@@ -162,7 +162,7 @@
const vars=document.documentElement.style;
const txtIn=document.getElementById('text-inp');
const noHover=matchMedia('(hover:none)');
- let spd=80,sep='✦';
+ let spd=80,separator='✦';
function makeItem(text,sep,reverse){
const item=document.createElement('div');item.className='marq-item'+(reverse?' rev-row':'');
@@ -207,9 +207,9 @@
const text=getContent();
const frac=progressOf(stage.querySelector('.marq-track'));
stage.innerHTML='';
- buildRow(text,sep,false,'');
- buildRow(text,sep,true,'accent');
- buildRow(text+' '+sep+' '+text,sep,false,'');
+ buildRow(text,separator,false,'');
+ buildRow(text,separator,true,'accent');
+ buildRow(text+' '+separator+' '+text,separator,false,'');
document.querySelectorAll('.marq-track').forEach(t=>updateSpeed(t,frac));
}
@@ -235,9 +235,10 @@
choices('speed-seg',d=>{spd=+d.spd;refreshSpeeds()});
choices('size-seg',d=>{vars.setProperty('--marq-size',d.size+'px');rebuild()});
choices('gap-seg',d=>{vars.setProperty('--marq-gap',d.gap+'px');rebuild()});
- choices('sep-seg',d=>{sep=d.sep;rebuild()});
+ choices('sep-seg',d=>{separator=d.sep;rebuild()});
rebuild();
+ if(document.fonts)document.fonts.ready.then(rebuild); // the site font can still be loading when the rows are first measured
</script>
</body>
</html>
diff --git a/animations/05-text-typography/outline-to-fill/index.html b/animations/05-text-typography/outline-to-fill/index.html
index a7a2ee63..088d878f 100644
--- a/animations/05-text-typography/outline-to-fill/index.html
+++ b/animations/05-text-typography/outline-to-fill/index.html
@@ -306,6 +306,7 @@
txtIn.addEventListener('input',()=>{applyText(txtIn.value.trim()?txtIn.value.toUpperCase():'OUTLINE')});
window.addEventListener('resize',fitText);
apply();applyDir();fitText();
+ if(document.fonts)document.fonts.ready.then(fitText); // the site font can still be loading when fitText() first runs
</script>
</body>
</html>