176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
fix: keep Text on a Path's curve full and its speed steady, and tidy both pages after review
matin7ec1195216f5
diff --git a/animations/05-text-typography/text-gradient-animation/index.html b/animations/05-text-typography/text-gradient-animation/index.htmlindex f1b11643..2b9852d4 100644--- a/animations/05-text-typography/text-gradient-animation/index.html+++ b/animations/05-text-typography/text-gradient-animation/index.html@@ -205,10 +205,22 @@c1Setting.hidden=!isCustom;c2Setting.hidden=!isCustom;});- choices('speed-seg',d=>{vars.setProperty('--grad-dur',d.dur)});+ // How far through its pass (0 to 1) an animation is. It is read from the animation itself, so it also holds+ // while the animation is paused or slowed down.+ function progressOf(a){+ const dur=a.effect.getComputedTiming().duration;+ return a.currentTime!=null&&dur>0?(a.currentTime%dur)/dur:0;+ }+ // A new --grad-dur keeps the time already played, not the progress, so the colors would jump to another point+ // of the pass. Put each animation back at the progress it had, measured against the new duration.+ choices('speed-seg',d=>{+ const kept=gradText.getAnimations().map(a=>[a,progressOf(a)]);+ vars.setProperty('--grad-dur',d.dur);+ kept.forEach(([a,progress])=>{a.currentTime=progress*parseFloat(d.dur)*1000});+ });choices('c1-sw',d=>{vars.setProperty('--c1',d.c)});choices('c2-sw',d=>{vars.setProperty('--c2',d.c)});- txtIn.addEventListener('input',()=>{gradText.textContent=txtIn.value||'Flow'});+ txtIn.addEventListener('input',()=>{gradText.textContent=txtIn.value.trim()||'Flow'});</script></body></html>diff --git a/animations/05-text-typography/text-on-path/README.md b/animations/05-text-typography/text-on-path/README.mdindex 2f252352..eab75eda 100644--- a/animations/05-text-typography/text-on-path/README.md+++ b/animations/05-text-typography/text-on-path/README.md@@ -10,7 +10,7 @@ Text on a path lets a line of type follow a curve instead of a straight line. Th- Looping marquees that follow a shape rather than a flat line## How it works-The path is declared once inside `<defs>` with an `id`. A `<textPath href="#curve">` references it, and the glyphs lay themselves along the curve automatically. Each animation frame advances `startOffset` by a small percentage, wrapping at 100%:+The path is declared once inside `<defs>` with an `id`. A `<textPath href="#curve">` references it, and the glyphs lay themselves along the curve automatically:```html<defs><path id="curve" d="M20,180 C120,60 240,300 340,180 S560,60 620,180"/></defs>@@ -19,21 +19,30 @@ The path is declared once inside `<defs>` with an `id`. A `<textPath href="#curv</text>```+Glyphs that run past the end of the path are not drawn, so a single copy of the phrase would leave the end of the curve empty as it slides along. Instead the phrase is repeated until it covers the whole path plus one extra copy. The length of one copy, as a percentage of the path, is measured as two copies minus one (with `getSubStringLength()`), so spaces that collapse at the ends cancel out. The start point then only ever moves within one copy's length, from one copy before the path up to the path's start. When it wraps, an identical copy is already in place, so the jump cannot be seen:+```js-function loop(){- offset=(offset+speed)%100;- tp.setAttribute('startOffset',offset+'%');+// unit: the length of one copy of the phrase, as a percentage of the path+tp.textContent = phrase.repeat(Math.ceil(100 / unit) + 1); // the whole path plus one extra copy++function loop(now) {+ const dt = last === null ? 0 : Math.min(now - last, 50); // milliseconds since the last frame+ last = now;+ offset = (offset + speed * dt / (1000 / 60)) % unit; // speed: % of the path per 1/60 s; wraps after one copy+ tp.setAttribute('startOffset', (offset - unit) + '%'); // always between -unit and 0requestAnimationFrame(loop);}```-Switching path shape swaps the `d` attribute on the same `<path>` — the text re-flows onto the new geometry with no other changes. The dashed guide is a `<use href="#curve">` of the identical path, toggled by opacity.+The movement follows the clock, not the frame count, so a 120 Hz screen is no faster than a 60 Hz one. The first frame after a start only records the time, and a long gap between frames counts for at most 50 ms, so starting again after a pause does not leap.++Switching path shape swaps the `d` attribute on the same `<path>`, and typing a new phrase replaces the text. Either way, one copy is now a different share of the curve, so the phrase is measured and repeated again, and the start point is written straight away, kept within the new copy length. That keeps the whole curve covered even while the animation is paused. The dashed guide is a `<use href="#curve">` of the identical path, toggled by opacity.## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|| Path shape | Wave | The curve the text follows: a wave, an arc or a full circle |-| Speed | Normal | How far the text moves each frame: slow is 0.25%, normal 0.4% and fast 0.65% of the path |+| Speed | Normal | How far the text moves every sixtieth of a second: slow is 0.25%, normal 0.4% and fast 0.65% of the path (15%, 24% and 39% a second) || Shows the path | on | Draws the curve as a dashed line under the text || Your text | FOLLOW THE CURVE · | The phrase that travels; end it with a separator so the repeats read on |diff --git a/animations/05-text-typography/text-on-path/index.html b/animations/05-text-typography/text-on-path/index.htmlindex 50152a02..79b3de71 100644--- a/animations/05-text-typography/text-on-path/index.html+++ b/animations/05-text-typography/text-on-path/index.html@@ -156,7 +156,9 @@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,unit=100;+ const DEFAULT_TEXT='FOLLOW THE CURVE · ';+ const FRAME=1000/60; // the speeds are a share of the path per 1/60 s, so a 120 Hz screen is no faster than a 60 Hz one+ let offset=0,speed=0.4,raf=null,last=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.@@ -164,24 +166,34 @@// 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=txtIn.value||' ';+ // a blank field falls back to the default phrase; a typed phrase is kept as typed, including its trailing space+ const s=txtIn.value.trim()?txtIn.value:DEFAULT_TEXT;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);+ // The copy length and the number of copies just changed. Keep the start point within one copy and write it+ // now: loop() would do it, but it is not running while paused, and a stale start point can leave the end of the curve empty.+ offset%=unit;+ tp.setAttribute('startOffset',(offset-unit)+'%');}- function step(){ return slowTog.checked?speed/3:speed; }- function loop(){- offset=(offset+step())%unit;+ function step(dt){ return (slowTog.checked?speed/3:speed)*dt/FRAME; }+ function loop(now){+ // The first frame after start() has no earlier frame to measure from, so it stays put; a long gap+ // between frames (a background tab) counts for at most 50 ms.+ const dt=last===null?0:Math.min(now-last,50);+ last=now;+ offset=(offset+step(dt))%unit;tp.setAttribute('startOffset',(offset-unit)+'%');raf=requestAnimationFrame(loop);}- function start(){ if(raf)return; raf=requestAnimationFrame(loop); }+ function start(){ if(raf)return; last=null; raf=requestAnimationFrame(loop); }// Registered at the top level, before the shared script (deferred) can run: under reduced motion it pauses// the loop on arrival, which this listener must catch. loop() requests exactly one next frame and stores it// in raf; Pause cancels that frame and clears raf, and Play calls start(), which continues from the current- // offset. start() keeps its if(raf)return guard, so Play never starts a second loop.+ // offset and forgets the time of the last frame, so the pause is not counted as movement. start() keeps its+ // if(raf)return guard, so Play never starts a second loop.document.addEventListener('hb:pause',e=>{if(e.detail.paused){cancelAnimationFrame(raf);raf=null;}else start();