Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

feat: move SVG Path Animation to the guided-steps page

matin55e29175d4b3
diff --git a/animations/06-3d-advanced/svg-path-animation/README.md b/animations/06-3d-advanced/svg-path-animation/README.md
index a512b91f..54246197 100644
--- a/animations/06-3d-advanced/svg-path-animation/README.md
+++ b/animations/06-3d-advanced/svg-path-animation/README.md
@@ -1,7 +1,7 @@
# SVG Path Animation
## What it is
-SVG path animation uses `stroke-dasharray` and `stroke-dashoffset` to reveal an SVG stroke progressively from one end to the other, giving the impression of a path being drawn in real time. The path is always fully rendered in the DOM — only its visibility changes. This makes the technique accessible (the final shape is always present for screen readers) and easily reversible (animate offset back to hide).
+An SVG path animation makes a line drawing appear as if drawn by hand. Each line is hidden behind a dash exactly as long as the line, and sliding that dash away uncovers the line from one end to the other. The whole drawing is in the page from the start, with a label, so screen readers can always find it.
## When to use it
- Illustrated icon or logo reveals that "draw in" on page load
@@ -21,11 +21,10 @@ path.style.strokeDasharray = length;
path.style.strokeDashoffset = length; // fully hidden
path.style.transition = 'none';
-// Force browser to register the hidden state, then animate
-requestAnimationFrame(() => requestAnimationFrame(() => {
- path.style.transition = `stroke-dashoffset 1500ms ease-out`;
- path.style.strokeDashoffset = 0; // fully revealed
-}));
+// Make the browser apply the hidden state, then animate
+path.getBoundingClientRect();
+path.style.transition = 'stroke-dashoffset 1500ms ease-out';
+path.style.strokeDashoffset = 0; // fully revealed
```
For multiple paths in sequence, stagger the transitions with a delay per path:
@@ -35,12 +34,13 @@ paths.forEach((path, i) => {
const len = path.getTotalLength();
path.style.strokeDasharray = len;
path.style.strokeDashoffset = len;
- path.style.transitionDelay = `${i * 300}ms`;
+ path.style.transition = 'none';
- requestAnimationFrame(() => requestAnimationFrame(() => {
- path.style.transition = `stroke-dashoffset 700ms ease-out ${i * 300}ms`;
+ setTimeout(() => {
+ path.getBoundingClientRect(); // apply the hidden state first
+ path.style.transition = 'stroke-dashoffset 700ms ease-out';
path.style.strokeDashoffset = 0;
- }));
+ }, i * 300);
});
```
@@ -56,10 +56,13 @@ path.addEventListener('transitionend', () => {
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Duration | 1500ms | Faster = snappy; slower = deliberate hand-drawing feel |
-| Easing | ease-out | Matches natural drawing speed (fast start, slow finish); linear = mechanical |
-| Stroke width | 2px | Thinner = precise/technical; thicker = bold/illustrative |
-| Stagger delay | 300ms | Gap between sequential path starts |
+| Drawing | Icon | What is drawn: a house with a star, a flowing signature, or a circle logo |
+| Speed | Normal | How long each line takes to draw: slow is 2400ms, normal 1500ms and fast 900ms; each next line starts after 30% of that |
+| Line thickness | Medium | Thin is 1px, medium 2px and thick 4px; thin looks precise, thick looks bold |
+| Feel | Smooth | Smooth slows at the end, like a hand finishing a stroke; Gentle eases in and out; Even keeps one pace |
+| Line color | Blue | The color of the lines, and of the fill |
+| Starts from the other end | off | Draws each line from its end back to its start |
+| Fills in at the end | off | Fills the shapes with a light tint of the line color once the lines are drawn |
## Production notes
- **`getTotalLength()` is required**: hardcoding `stroke-dasharray` breaks when the path changes. Always measure at runtime. For SVGs loaded asynchronously, measure after the element is added to the DOM.
@@ -69,6 +72,6 @@ path.addEventListener('transitionend', () => {
- **Framer Motion**: `<motion.path initial={{ pathLength: 0 }} animate={{ pathLength: 1 }} />` — `pathLength` is a 0–1 shorthand that internally manages `dasharray`/`dashoffset`.
## See also
-- [Checkmark Draw](../../04-micro-interactions/checkmark-draw/) — the same technique applied to UI success states
-- [Text Clip-Path Reveal](../../05-text-typography/text-clip-path-reveal/) — a conceptually similar progressive reveal for text
-- [Outline to Fill](../../05-text-typography/outline-to-fill/) — SVG stroke → fill transition for text
+- [Checkmark Draw](../../04-micro-interactions/checkmark-draw/) — the same technique for a success tick
+- [Text Clip-Path Reveal](../../05-text-typography/text-clip-path-reveal/) — lines of text uncovered one by one
+- [Outline to Fill](../../05-text-typography/outline-to-fill/) — hollow letters fill with color
diff --git a/animations/06-3d-advanced/svg-path-animation/index.html b/animations/06-3d-advanced/svg-path-animation/index.html
index d92f672f..f9653bfd 100644
--- a/animations/06-3d-advanced/svg-path-animation/index.html
+++ b/animations/06-3d-advanced/svg-path-animation/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SVG Path Animation — Animation Handbook</title>
- <meta name="description" content="stroke-dashoffset reveals a path from its start point — set dasharray to path length, animate offset to 0.">
+ <meta name="description" content="A line drawing draws itself, stroke by stroke. Best for icons and logos.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/svg-path-animation/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,229 +12,256 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="SVG Path Animation — Animation Handbook">
- <meta property="og:description" content="stroke-dashoffset reveals a path from its start point — set dasharray to path length, animate offset to 0.">
+ <meta property="og:description" content="A line drawing draws itself, stroke by stroke. Best for icons and logos.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/svg-path-animation/">
<meta property="og:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="SVG Path Animation — Animation Handbook">
- <meta name="twitter:description" content="stroke-dashoffset reveals a path from its start point — set dasharray to path length, animate offset to 0.">
+ <meta name="twitter:description" content="A line drawing draws itself, stroke by stroke. Best for icons and logos.">
<meta name="twitter:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
- <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "SVG Path Animation", "name": "SVG Path Animation", "description": "stroke-dashoffset reveals a path from its start point — set dasharray to path length, animate offset to 0.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/svg-path-animation/", "inLanguage": "en", "articleSection": "3D & Advanced", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, 3D & Advanced, SVG Path Animation"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "SVG Path Animation", "name": "SVG Path Animation", "description": "A line drawing draws itself, stroke by stroke. Best for icons and logos.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/svg-path-animation/", "inLanguage": "en", "articleSection": "3D & Advanced", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, 3D & Advanced, SVG Path Animation"}</script>
<style>
- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-700.woff2') format('woff2');font-weight:700;font-display:swap}
- @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:#3fd6c4;--ui-text:#f4f4f2;--ui-muted:#77777e;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px;--draw-dur:1500ms;--draw-ease:ease-out;--stroke-w:2;--stroke-color:#58a6ff}
+ :root{--ui-accent:#3fd6c4;--stroke-w:2;--stroke-color:#58a6ff;--fill-dur:400ms}
*,*::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:16px;padding:24px;position:relative}
- svg{width:100%;max-width:400px;overflow:visible}
+ .stage{position:relative;display:flex;align-items:center;justify-content:center;padding:24px;background:#04060c}
+ /* max-height keeps the whole drawing inside a short stage (the box is 400 x 260 at full size) */
+ .stage svg{width:100%;max-width:400px;max-height:100%;overflow:visible}
+ /* transparent, not none: a fill can only fade in from a color */
.draw-path{
- fill:none;fill-opacity:.15;stroke:var(--stroke-color);stroke-width:var(--stroke-w);
+ fill:transparent;fill-opacity:.15;stroke:var(--stroke-color);stroke-width:var(--stroke-w);
stroke-linecap:round;stroke-linejoin:round;
stroke-dasharray:1;stroke-dashoffset:1;
}
- .draw-path.fill-done{fill:var(--stroke-color);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: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 */
- 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)}
- .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
- .kv .v{color:var(--ui-text)}
- .div{height:1px;background:var(--ui-border)}
- .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)}
- 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: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}}
+ .draw-path.fill-done{fill:var(--stroke-color);transition:fill var(--fill-dur) ease}
@media(prefers-reduced-motion:reduce){.draw-path{stroke-dashoffset:0!important;transition:none!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}
-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: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}
-.ah-sep{width:1px;height:16px;background:var(--ah-line);margin:0 4px}
-.ah-copied{color:var(--ah-accent)!important}
-@media(max-width:600px){.ah-bar .ah-hideSm{display:none}}
-@media print{.ah-bar{display:none}body{padding-top:0}}
-</style>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
-<body>
-<div class="ah-bar" role="navigation" aria-label="Animation Handbook"><a class="ah-home" href="../../../">← Animation Handbook</a><span class="ah-actions"><a class="ah-hideSm" href="../noise-based-motion/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../chromatic-aberration/" rel="next" title="Next">Next ›</a><span class="ah-sep ah-hideSm"></span><button type="button" id="ah-copy" class="ah-hideSm">Copy source</button><a class="ah-hideSm" href="https://github.com/matinmonshizadeh/animation-handbook/blob/main/animations/06-3d-advanced/svg-path-animation/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-<header>
- <h1>SVG Path Animation</h1>
- <p>stroke-dashoffset reveals a path from its start point — set dasharray to path length, animate offset to 0.</p>
-</header>
-<div class="layout">
- <div class="stage">
- <div class="preset-tabs" id="tabs"></div>
- <svg id="svg-stage" viewBox="0 0 400 260">
- <g id="drawing-group"></g>
- </svg>
- <div class="svg-label" id="svg-label">Line Drawing</div>
- </div>
- <aside>
- <p class="note">path.getTotalLength() gives the full stroke length. Set stroke-dasharray to that value and stroke-dashoffset from length→0 to draw the path in.</p>
- <div class="lbl">Draw Duration</div>
- <div class="sr"><input type="range" id="dur-sl" min="300" max="4000" value="1500" step="100"><span class="sv" id="dur-v">1.5s</span></div>
- <div class="lbl">Easing</div>
- <select id="ease-sel">
- <option value="ease-out" selected>Ease out</option>
- <option value="linear">Linear</option>
- <option value="ease-in-out">Ease in-out</option>
- <option value="cubic-bezier(.2,.7,.3,1)">Smooth</option>
- </select>
- <div class="lbl">Stroke Width</div>
- <div class="sr"><input type="range" id="sw-sl" min="1" max="6" value="2" step="0.5"><span class="sv" id="sw-v">2px</span></div>
- <div class="lbl">Stroke Color</div>
- <input type="color" id="color-pick" value="#58a6ff" aria-label="Stroke color">
- <label class="tog"><input type="checkbox" id="rev-tog"><span>Draw in reverse</span></label>
- <label class="tog"><input type="checkbox" id="fill-tog"><span>Fill at end</span></label>
- <div class="div"></div>
- <button class="rst" id="replay-btn">↺ Replay</button>
- <label class="tog"><input type="checkbox" id="loop-tog"><span>Auto-loop</span></label>
- <div class="kv"><span>Path length</span><span class="v" id="path-len">—</span></div>
- </aside>
-</div>
-<script>
-const PRESETS=[
- {
- name:'Icon',label:'Complex Line Drawing',
- paths:[
- // Abstract geometric icon: house + star shapes
- 'M 60 200 L 60 120 L 200 40 L 340 120 L 340 200 Z',
- 'M 160 200 L 160 150 L 240 150 L 240 200',
- 'M 200 40 L 215 80 L 260 80 L 225 105 L 240 148 L 200 122 L 160 148 L 175 105 L 140 80 L 185 80 Z',
- ]
- },
- {
- name:'Signature',label:'Signature',
- paths:[
- // Cursive-style flowing path
- 'M 30 180 C 40 160 60 140 80 150 C 100 160 90 190 110 180 C 130 170 120 140 145 145 C 165 150 160 175 180 170 C 195 165 190 145 210 148 C 230 151 225 178 250 172 C 270 167 265 140 290 145 C 310 150 310 175 340 170 C 360 166 365 140 380 145',
- ]
- },
- {
- name:'Logo',label:'Logo Mark',
- paths:[
- // Circle + inner geometric shape
- 'M 200 10 A 120 120 0 1 1 199.99 10',
- 'M 200 80 L 240 150 L 200 130 L 160 150 Z',
- 'M 200 130 L 200 185',
- ]
- }
-];
+<body class="hb" data-hb-kind="once" data-hb-autoplay>
+<nav class="hb-bar" aria-label="Animation Handbook">
+ <a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>
+ <span class="hb-pager"><a href="../noise-based-motion/" rel="prev" aria-label="Previous: Noise-Based Motion"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Noise-Based Motion</span></a><a href="../chromatic-aberration/" rel="next" aria-label="Next: Chromatic Aberration"><span><span class="hb-dir">Next: </span>Chromatic Aberration</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>
+</nav>
+<main class="hb-page">
+ <header class="hb-head">
+ <p class="hb-cat">06.09 · 3D &amp; Advanced</p>
+ <h1>SVG Path Animation</h1>
+ <p class="hb-lede">A line drawing draws itself, stroke by stroke. Best for icons and logos.</p>
+ </header>
-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');
-const svgLabel=document.getElementById('svg-label');
-const pathLenEl=document.getElementById('path-len');
+ <section class="hb-step hb-watch" aria-labelledby="hb-watch-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">1</span>
+ <div><h2 id="hb-watch-title">Watch it</h2><p>It plays by itself. Turn on slow motion to see each part of the movement.</p></div>
+ </div>
+ <div class="stage hb-dots">
+ <svg id="svg-stage" viewBox="0 0 400 260" role="img" aria-label="House and star icon">
+ <g id="drawing-group"></g>
+ </svg>
+ </div>
+ <div class="hb-player">
+ <button class="hb-play" type="button" id="btn-play" data-hb-replay><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>Replay</button>
+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="loop-tog" data-hb-loop autocomplete="off"><span>Loop</span></label>
+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo autocomplete="off"><span>Slow motion</span></label>
+ </div>
+ </section>
-function getDur(){return+document.getElementById('dur-sl').value}
-function getEase(){return document.getElementById('ease-sel').value}
-function getReverse(){return document.getElementById('rev-tog').checked}
-function getFill(){return document.getElementById('fill-tog').checked}
+ <section class="hb-step hb-try" aria-labelledby="hb-try-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">2</span>
+ <div><h2 id="hb-try-title">Try it</h2><p>Change a setting and the animation plays again.</p></div>
+ </div>
+ <div class="hb-settings">
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="drawing-lbl">Drawing</p>
+ <div class="seg" id="drawing-seg" role="group" aria-labelledby="drawing-lbl">
+ <button type="button" data-drawing="0" class="on" aria-pressed="true">Icon</button>
+ <button type="button" data-drawing="1" aria-pressed="false">Signature</button>
+ <button type="button" data-drawing="2" aria-pressed="false">Logo</button>
+ </div>
+ <p class="hb-hint">What is drawn: an icon, a signature or a logo.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="speed-lbl">Speed</p>
+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">
+ <button type="button" data-ms="2400" aria-pressed="false">Slow</button>
+ <button type="button" data-ms="1500" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-ms="900" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">How long each line takes to draw.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="width-lbl">Line thickness</p>
+ <div class="seg" id="width-seg" role="group" aria-labelledby="width-lbl">
+ <button type="button" data-w="1" aria-pressed="false">Thin</button>
+ <button type="button" data-w="2" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-w="4" aria-pressed="false">Thick</button>
+ </div>
+ <p class="hb-hint">Thin looks precise; thick looks bold.</p>
+ </div>
+ </div>
+ <details class="hb-options">
+ <summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>
+ <div class="hb-settings">
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="feel-lbl">Feel</p>
+ <div class="seg" id="feel-seg" role="group" aria-labelledby="feel-lbl">
+ <button type="button" data-ease="ease-out" class="on" aria-pressed="true">Smooth</button>
+ <button type="button" data-ease="ease-in-out" aria-pressed="false">Gentle</button>
+ <button type="button" data-ease="linear" aria-pressed="false">Even</button>
+ </div>
+ <p class="hb-hint">Smooth slows at the end, like a hand finishing.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="color-lbl">Line color</p>
+ <div class="swatches" id="color-sw" role="group" aria-labelledby="color-lbl">
+ <button type="button" aria-pressed="false" aria-label="Pink" data-color="#ff6f8b" style="background:#ff6f8b"></button>
+ <button type="button" aria-pressed="false" aria-label="White" data-color="#f4f4f2" style="background:#f4f4f2"></button>
+ <button type="button" class="on" aria-pressed="true" aria-label="Blue" data-color="#58a6ff" style="background:#58a6ff"></button>
+ <button type="button" aria-pressed="false" aria-label="Purple" data-color="#d2a8ff" style="background:#d2a8ff"></button>
+ <button type="button" aria-pressed="false" aria-label="Green" data-color="#56d364" style="background:#56d364"></button>
+ <button type="button" aria-pressed="false" aria-label="Orange" data-color="#ffa657" style="background:#ffa657"></button>
+ </div>
+ <p class="hb-hint">The color of the lines.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-switch-row"><span>Starts from the other end</span><input class="hb-switch" type="checkbox" role="switch" id="rev-tog" autocomplete="off"></label>
+ <p class="hb-hint">Draws each line from its end back to its start.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-switch-row"><span>Fills in at the end</span><input class="hb-switch" type="checkbox" role="switch" id="fill-tog" autocomplete="off"></label>
+ <p class="hb-hint">Fills the shapes once the lines are drawn.</p>
+ </div>
+ </div>
+ </details>
+ </section>
-// Build tab buttons
-PRESETS.forEach((p,i)=>{
- const b=document.createElement('button');b.className='ptab'+(i===0?' active':'');b.textContent=p.name;
- b.addEventListener('click',()=>{current=i;document.querySelectorAll('.ptab').forEach((t,j)=>t.classList.toggle('active',j===i));replay();});
- tabs.appendChild(b);
-});
+ <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">3</span>
+ <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>
+ </div>
+ <div class="hb-card">
+ <p class="hb-prompt">Add a self-drawing line to [your icon, logo or signature, drawn as SVG lines]. Measure the length of each line, hide it behind a dash exactly as long as the line, then slide the dash away so the line appears from one end to the other, as if drawn by hand. Draw several lines one after another, each starting a little after the one before. When the settings include it, fill the shapes once the lines are done. The finished drawing should be there for screen readers from the start. If the visitor has reduced motion turned on, show the drawing complete. Match the settings listed below.</p>
+ <div class="hb-chips-box" hidden>
+ <p class="hb-chips-title">Your settings</p>
+ <ul class="hb-chips"></ul>
+ </div>
+ <div class="hb-copy-row">
+ <button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>
+ <p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p>
+ </div>
+ </div>
+ </section>
-function buildPaths(){
- group.innerHTML='';
- const p=PRESETS[current];
- svgLabel.textContent=p.label;
- const els=p.paths.map(d=>{
- const path=document.createElementNS('http://www.w3.org/2000/svg','path');
- path.setAttribute('d',d);
- path.className.baseVal='draw-path';
- group.appendChild(path);
- return path;
- });
- return els;
-}
+ <section class="hb-about" aria-labelledby="hb-what-title">
+ <div class="hb-what">
+ <h2 id="hb-what-title">What it is</h2>
+ <div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>
+ </div>
+ <div class="hb-fit">
+ <h2>Good for</h2>
+ <ul class="hb-tags hb-good"><li>Icons</li><li>Logos</li><li>Signatures</li><li>Illustrations</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Photos</li><li>Body text</li></ul>
+ </div>
+ </section>
-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';
+ <section class="hb-related" aria-labelledby="hb-related-title" hidden>
+ <h2 id="hb-related-title">Similar animations</h2>
+ <div class="hb-rel-list"></div>
+ </section>
+</main>
+<footer class="hb-foot"><span>Animation Handbook</span><a href="#top">Back to top ↑</a></footer>
+<script>
+ const DRAWINGS=[
+ {label:'House and star icon',paths:[
+ 'M 60 200 L 60 120 L 200 40 L 340 120 L 340 200 Z',
+ 'M 160 200 L 160 150 L 240 150 L 240 200',
+ 'M 200 40 L 215 80 L 260 80 L 225 105 L 240 148 L 200 122 L 160 148 L 175 105 L 140 80 L 185 80 Z'
+ ]},
+ {label:'Signature',paths:[
+ 'M 30 180 C 40 160 60 140 80 150 C 100 160 90 190 110 180 C 130 170 120 140 145 145 C 165 150 160 175 180 170 C 195 165 190 145 210 148 C 230 151 225 178 250 172 C 270 167 265 140 290 145 C 310 150 310 175 340 170 C 360 166 365 140 380 145'
+ ]},
+ {label:'Logo mark',paths:[
+ 'M 200 10 A 120 120 0 1 1 199.99 10',
+ 'M 200 80 L 240 150 L 200 130 L 160 150 Z',
+ 'M 200 130 L 200 185'
+ ]}
+ ];
+ const svg=document.getElementById('svg-stage');
+ const group=document.getElementById('drawing-group');
+ const vars=document.documentElement.style;
+ const loopTog=document.getElementById('loop-tog'),slowTog=document.getElementById('slow-tog');
+ const revTog=document.getElementById('rev-tog'),fillTog=document.getElementById('fill-tog');
+ const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
+ let current=0,dur=1500,ease='ease-out',timers=[];
- paths.forEach((path,i)=>{
- const len=path.getTotalLength();
- path.style.strokeDasharray=len;
- path.style.strokeDashoffset=rev?-len:len;
- 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}`;
+ function speed(){return slowTog.checked?dur*3:dur}
+ // Drops a timer's id once it fires, so `timers` only ever holds ones still pending (not every id ever
+ // scheduled) — Loop can run for a long time without the array growing without bound.
+ function later(fn,wait){
+ const id=setTimeout(()=>{
+ const i=timers.indexOf(id);
+ if(i>-1)timers.splice(i,1);
+ fn();
+ },wait);
+ timers.push(id);
+ }
+ // Rebuilds the paths of the chosen drawing, and names it for screen readers.
+ function buildPaths(){
+ const drawing=DRAWINGS[current];
+ svg.setAttribute('aria-label',drawing.label);
+ group.replaceChildren();
+ return drawing.paths.map(d=>{
+ const path=document.createElementNS('http://www.w3.org/2000/svg','path');
+ path.setAttribute('d',d);
+ path.setAttribute('class','draw-path');
+ group.appendChild(path);
+ return path;
+ });
+ }
+ // One play rebuilds the paths hidden and draws them one after another, each starting a little after the
+ // one before. While Loop is on, the finished drawing holds 1200ms; whether it then vanishes and draws again
+ // is decided right after that hold, from Loop's value at that moment, so switching Loop off during the hold
+ // leaves the drawing shown. Slow motion stretches the draws and the waits for them, not the hold.
+ function cycle(){
+ vars.setProperty('--fill-dur',slowTog.checked?'1200ms':'400ms');
+ const paths=buildPaths(),ms=speed(),gap=ms*0.3,rev=revTog.checked;
+ paths.forEach(path=>{
+ const len=path.getTotalLength();
+ path.style.strokeDasharray=len;
+ path.style.strokeDashoffset=rev?-len:len;
+ path.style.transition='none';
+ });
+ paths.forEach((path,i)=>later(()=>{
+ path.getBoundingClientRect(); // apply the hidden state first, so the slide has a start value
+ path.style.transition=`stroke-dashoffset ${ms}ms ${ease}`;
path.style.strokeDashoffset=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){
- loopTimer=setTimeout(replay,1200);
- }
- },dur+50);
- }
- },delay+20);
- });
-}
-
-function replay(){
- clearTimeout(loopTimer);animating=false;
- const paths=buildPaths();
- paths.forEach(p=>p.classList.remove('fill-done'));
- animate(paths);
-}
-
-document.getElementById('replay-btn').addEventListener('click',replay);
-document.getElementById('dur-sl').addEventListener('input',e=>{
- document.getElementById('dur-v').textContent=(e.target.value/1000).toFixed(1)+'s';
- document.documentElement.style.setProperty('--draw-dur',e.target.value+'ms');
-});
-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.getElementById('color-pick').addEventListener('input',e=>{
- document.documentElement.style.setProperty('--stroke-color',e.target.value);
-});
-document.getElementById('loop-tog').addEventListener('change',e=>{
- if(!e.target.checked){clearTimeout(loopTimer);return}
- if(!animating)replay();
-});
+ },20+i*gap));
+ later(()=>{
+ if(fillTog.checked)paths.forEach(path=>{path.style.transition='';path.classList.add('fill-done')});
+ if(!loopTog.checked||!motionOk)return;
+ later(()=>{if(loopTog.checked)cycle()},1200);
+ },20+(paths.length-1)*gap+ms+50);
+ }
+ function play(){timers.forEach(clearTimeout);timers=[];cycle()}
-replay();
+ document.getElementById('btn-play').addEventListener('click',play);
+ loopTog.addEventListener('change',()=>{if(loopTog.checked)play()});
+ function choices(id,pick){
+ const buttons=document.querySelectorAll('#'+id+' button');
+ buttons.forEach(b=>b.addEventListener('click',()=>{
+ buttons.forEach(x=>{x.classList.toggle('on',x===b);x.setAttribute('aria-pressed',String(x===b))});
+ pick(b.dataset);
+ }));
+ }
+ choices('drawing-seg',d=>{current=+d.drawing});
+ choices('speed-seg',d=>{dur=+d.ms});
+ choices('width-seg',d=>{vars.setProperty('--stroke-w',d.w)});
+ choices('feel-seg',d=>{ease=d.ease});
+ choices('color-sw',d=>{vars.setProperty('--stroke-color',d.color)});
</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>
</html>
diff --git a/index.html b/index.html
index 266a3415..46589d3b 100644
--- a/index.html
+++ b/index.html
@@ -1016,7 +1016,7 @@ const CATS=[
['glassmorphism-animated','Glassmorphism Animated','Frosted glass cards blur the colors behind them. Best for cards and panels.'],
['webgl-shader-animation','WebGL Shader Animation','Moving color patterns computed for every pixel. Best for bold backgrounds.'],
['noise-based-motion','Noise-Based Motion','Smooth noise makes dots sway and a blob ripple. Best for calm backgrounds.'],
- ['svg-path-animation','SVG Path Animation','stroke-dashoffset reveals three SVG drawings — icon, signature, and logo mark.'],
+ ['svg-path-animation','SVG Path Animation','A line drawing draws itself, stroke by stroke. Best for icons and logos.'],
['chromatic-aberration','Chromatic Aberration','RGB channels offset via mix-blend-mode: screen — static, pulse, and glitch modes.'],
['2-5d-pseudo-3d','2.5D / Pseudo-3D','Seven depth layers parallax at different rates — mouse-driven or auto-panning camera.'],
['ray-marching-sdf','Ray Marching / SDF','3D scene entirely in a fragment shader — sphere blend, boolean ops, infinite repetition.'],