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 Line Draw on Scroll to the guided-steps page

matinb953f26bcfcf
diff --git a/animations/01-scroll-based/svg-line-draw/README.md b/animations/01-scroll-based/svg-line-draw/README.md
index d4949003..5cd93733 100644
--- a/animations/01-scroll-based/svg-line-draw/README.md
+++ b/animations/01-scroll-based/svg-line-draw/README.md
@@ -4,7 +4,7 @@
## What it is
-A long SVG path embedded in the scrolling content that draws itself with the stroke-dash trick as the reader scrolls down it. The route is part of the page — a tall, winding line you physically travel along — and labelled waypoints pop in as the drawn tip reaches them. This is the classic "journey map" storytelling pattern: hiking routes, company timelines, delivery tracking, process walkthroughs.
+A scroll-drawn line is a long winding route that draws itself as you scroll down it, like a journey being traced on a map. Labelled stops along the way pop in as the line reaches them, and scrolling back up erases the line again. A faint dashed copy of the route shows where it is heading.
## When to use it
@@ -33,24 +33,24 @@ Waypoints are placed at known fractions of the path, so their positions and trig
// at init: position each waypoint and store its length threshold
wp.len = LEN * wp.fraction;
const pt = path.getPointAtLength(wp.len);
-wp.group.setAttribute('transform', `translate(${pt.x} ${pt.y})`);
+wp.group.setAttribute('transform', `translate(${pt.x} ${pt.y}) scale(${k})`);
// per frame: a cheap comparison, class toggled only when the state changes
const on = drawn >= wp.len;
if (on !== wp.on) { wp.on = on; wp.group.classList.toggle('on', on); }
```
+Each stop is also scaled by `k`, which is 600 divided by the drawing's width on screen, so its dot and labels keep the same size on every screen while the route itself scales.
+
The pop itself is CSS — `.on` transitions the waypoint from `scale(.6)` and `opacity: 0` to full size, and scrolling back past a waypoint removes the class so it un-pops. Progress is clamped, never gated: jumping straight to the bottom draws the full route, returning to the top erases it, and there is no state to get stuck in between. A faint dashed copy of the path sits underneath the drawing stroke, so the reader always sees where the route is going before the line gets there.
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| `COMPLETE_AT` | 0.85 | Fraction of the scroll range at which the line finishes. Below 1, the route completes while the end is still in view instead of clipping at the viewport edge |
-| Easing | linear | Curve applied to progress before mapping to length. Linear keeps the tip 1:1 with scroll; ease-out front-loads the draw |
-| Waypoint fractions | 0.05 – 0.95 | Where along the path each marker sits and triggers, as a share of total length |
-| Pop transition | 350 ms, overshoot bezier | The scale/fade on waypoint entry. Removed entirely under `prefers-reduced-motion` |
-| Route height | ~2200 SVG units | How much scrolling the journey spans. Taller = slower, more deliberate travel |
+| Feel | Even | Even keeps the tip of the line level with your scroll; Smooth draws quickly at first and slows toward the end |
+| Shows the stops | on | Five labelled stops pop in as the line reaches them and hide again when you scroll back |
+| Line finishes | Normal | How far through the scrolling the line is complete: early at 70%, normal at 85% and at the end at 100%; finishing early shows the whole route before you reach the bottom |
## Production notes
@@ -63,6 +63,6 @@ The pop itself is CSS — `.on` transitions the waypoint from `scale(.6)` and `o
## See also
-- [Scrub Animation](../scrub-animation/) — a short *pinned* path used as a seek bar while content scrolls past it; this entry is the inverse layout — a long path living *in* the content, drawn as you travel down it.
-- [SVG Path Animation](../../06-3d-advanced/svg-path-animation/) — the same dash trick driven by time instead of scroll.
-- [Scrollytelling](../scrollytelling/) — the narrative framework this pattern usually lives inside.
+- [Scrub Animation](../scrub-animation/) — a short pinned path moves as you scroll; here a long path lives in the content
+- [SVG Path Animation](../../06-3d-advanced/svg-path-animation/) — drawings trace themselves over time instead of with the scroll
+- [Scrollytelling](../scrollytelling/) — a picture beside the text changes as a story scrolls by
diff --git a/animations/01-scroll-based/svg-line-draw/index.html b/animations/01-scroll-based/svg-line-draw/index.html
index f845065e..3fa9b624 100644
--- a/animations/01-scroll-based/svg-line-draw/index.html
+++ b/animations/01-scroll-based/svg-line-draw/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SVG Line Draw on Scroll — Animation Handbook</title>
- <meta name="description" content="A long winding route embedded in the page draws itself as you scroll down it, popping waypoints as the line reaches them.">
+ <meta name="description" content="A line draws itself along a route as you scroll. Best for timelines.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/svg-line-draw/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,139 +12,156 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="SVG Line Draw on Scroll — Animation Handbook">
- <meta property="og:description" content="A long winding route embedded in the page draws itself as you scroll down it, popping waypoints as the line reaches them.">
+ <meta property="og:description" content="A line draws itself along a route as you scroll. Best for timelines.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/svg-line-draw/">
<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 Line Draw on Scroll — Animation Handbook">
- <meta name="twitter:description" content="A long winding route embedded in the page draws itself as you scroll down it, popping waypoints as the line reaches them.">
+ <meta name="twitter:description" content="A line draws itself along a route as you scroll. Best for timelines.">
<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 Line Draw on Scroll", "name": "SVG Line Draw on Scroll", "description": "A long winding route embedded in the page draws itself as you scroll down it, popping waypoints as the line reaches them.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/svg-line-draw/", "inLanguage": "en", "articleSection": "Scroll-Based", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Scroll-Based, SVG Line Draw on Scroll"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "SVG Line Draw on Scroll", "name": "SVG Line Draw on Scroll", "description": "A line draws itself along a route as you scroll. Best for timelines.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/svg-line-draw/", "inLanguage": "en", "articleSection": "Scroll-Based", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Scroll-Based, SVG Line Draw on Scroll"}</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:#6ea8ff;
- --ui-text:#f4f4f2;--ui-muted:#77777e;--stage-h:620px;
- --disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace}
+ :root{--bg:#0b0b0d;--ui-accent:#6ea8ff;--ui-text:#f4f4f2;--ui-muted:#8a8a92}
*,*::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(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);overflow-y:scroll;scrollbar-width:none;
- border:1px solid var(--ui-border);border-radius:8px}
+ .stage{position:relative;overflow-y:auto;scrollbar-width:none;background:#0b0b0d}
.stage::-webkit-scrollbar{display:none}
/* The route lives IN the scrolling content — no pinning. Scrolling travels down it. */
.scene{padding:clamp(10px,2vw,20px)}
- .scene svg{display:block;width:100%;height:auto}
- .scene-cap{text-align:center;font-size:10px;color:var(--ui-muted);padding:8px 0 16px}
+ .scene svg{display:block;width:100%;height:auto;overflow:visible}
+ .scene-cap{text-align:center;font-size:13px;color:var(--ui-muted);padding:8px 0 16px}
.guide{fill:none;stroke:rgba(255,255,255,.13);stroke-width:2;stroke-dasharray:5 7;stroke-linecap:round}
.trail{fill:none;stroke:var(--ui-accent);stroke-width:3;stroke-linecap:round;stroke-linejoin:round}
.dot{fill:var(--bg);stroke:var(--ui-accent);stroke-width:2.5}
/* paint-order draws a stage-coloured outline under each label, so text stays
legible where the line runs behind it */
- .wp-label{font-family:var(--mono);font-size:13px;fill:var(--ui-text);
+ .wp-label{font-size:14px;font-weight:600;fill:var(--ui-text);
paint-order:stroke;stroke:var(--bg);stroke-width:5px;stroke-linejoin:round}
- .wp-sub{font-family:var(--mono);font-size:10px;fill:var(--ui-muted);
+ .wp-sub{font-size:12px;fill:var(--ui-muted);
paint-order:stroke;stroke:var(--bg);stroke-width:5px;stroke-linejoin:round}
.pop{opacity:0;transform:scale(.6);transform-box:fill-box;transform-origin:center;
transition:transform .35s cubic-bezier(.34,1.56,.64,1),opacity .25s ease-out}
.wp.on .pop{opacity:1;transform:scale(1)}
.no-wps #wps{display: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)}
- .tbl{display:flex;flex-direction:column;gap:2px}
- .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
- .kv .v{color:var(--ui-text);font-variant-numeric:tabular-nums}
- .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}
- .sr .sv{width:38px;text-align:right;color:var(--ui-text);font-variant-numeric:tabular-nums}
- 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}
- .chk{display:flex;align-items:center;gap:8px;font-size:10px;min-height:44px;cursor:pointer}
- .chk input{width:18px;height:18px;accent-color:var(--ui-accent);cursor:pointer}
- .div{height:1px;background:var(--ui-border)}
- @media(max-width:600px){
- .layout{flex-direction:column}aside{width:100%}
- /* in a column container `flex:1` makes flex-basis the height and overrides --stage-h */
- .stage{flex:none;width:100%}:root{--stage-h:480px}
- }
@media(prefers-reduced-motion:reduce){.pop{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}
-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=4">
+ <script src="../../../assets/js/demo-page.js?v=4" 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="../scroll-velocity-skew/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../scrollspy-nav/" 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/01-scroll-based/svg-line-draw/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-<header>
- <h1>SVG Line Draw on Scroll</h1>
- <p>A long winding route embedded in the page draws itself as you scroll down it, popping waypoints as the line reaches them.</p>
-</header>
+<body class="hb" data-hb-kind="scroll" 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="../scroll-velocity-skew/" rel="prev" aria-label="Previous: Scroll Velocity Skew"><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>Scroll Velocity Skew</span></a><a href="../scrollspy-nav/" rel="next" aria-label="Next: Scrollspy Navigation"><span><span class="hb-dir">Next: </span>Scrollspy Navigation</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">01.24 · Scroll-Based</p>
+ <h1>SVG Line Draw on Scroll</h1>
+ <p class="hb-lede">A line draws itself along a route as you scroll. Best for timelines.</p>
+ </header>
-<div class="layout">
- <div class="stage" id="stage">
- <div class="scene">
- <svg id="map" viewBox="0 0 600 2200" preserveAspectRatio="xMidYMin meet" aria-hidden="true">
- <!-- faint dashed guide shows the full route before it is drawn -->
- <path class="guide" d="M 300 80 C 510 160 530 300 340 400 C 150 500 90 620 260 730 C 440 840 520 960 340 1080 C 160 1200 100 1310 290 1410 C 490 1510 510 1650 310 1760 C 110 1870 150 2020 300 2120"/>
- <path id="trail" class="trail" d="M 300 80 C 510 160 530 300 340 400 C 150 500 90 620 260 730 C 440 840 520 960 340 1080 C 160 1200 100 1310 290 1410 C 490 1510 510 1650 310 1760 C 110 1870 150 2020 300 2120"/>
- <g id="wps">
- <g class="wp" data-f="0.05"><g class="pop"><circle class="dot" r="7"/><text class="wp-label" x="20" y="1">Depart</text><text class="wp-sub" x="20" y="17">km 0 — trailhead</text></g></g>
- <g class="wp" data-f="0.27"><g class="pop"><circle class="dot" r="7"/><text class="wp-label" x="-20" y="1" text-anchor="end">River crossing</text><text class="wp-sub" x="-20" y="17" text-anchor="end">km 12 — footbridge</text></g></g>
- <g class="wp" data-f="0.50"><g class="pop"><circle class="dot" r="7"/><text class="wp-label" x="20" y="1">Basecamp</text><text class="wp-sub" x="20" y="17">km 27 — overnight</text></g></g>
- <g class="wp" data-f="0.73"><g class="pop"><circle class="dot" r="7"/><text class="wp-label" x="-20" y="1" text-anchor="end">Summit ridge</text><text class="wp-sub" x="-20" y="17" text-anchor="end">km 39 — 2 410 m</text></g></g>
- <g class="wp" data-f="0.95"><g class="pop"><circle class="dot" r="7"/><text class="wp-label" x="20" y="1">Arrive</text><text class="wp-sub" x="20" y="17">km 46 — journey's end</text></g></g>
- </g>
- </svg>
- <div class="scene-cap">— end of route —</div>
+ <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">Scroll it</h2><p>Scroll inside the box, or press Play and it scrolls for you.</p></div>
+ </div>
+ <div class="stage" id="stage" tabindex="0" role="region" aria-label="A route that draws itself as you scroll">
+ <div class="scene">
+ <svg id="map" viewBox="0 0 600 2200" preserveAspectRatio="xMidYMin meet" aria-hidden="true">
+ <!-- faint dashed guide shows the full route before it is drawn -->
+ <path class="guide" d="M 300 80 C 510 160 530 300 340 400 C 150 500 90 620 260 730 C 440 840 520 960 340 1080 C 160 1200 100 1310 290 1410 C 490 1510 510 1650 310 1760 C 110 1870 150 2020 300 2120"/>
+ <path id="trail" class="trail" d="M 300 80 C 510 160 530 300 340 400 C 150 500 90 620 260 730 C 440 840 520 960 340 1080 C 160 1200 100 1310 290 1410 C 490 1510 510 1650 310 1760 C 110 1870 150 2020 300 2120"/>
+ <g id="wps">
+ <g class="wp" data-f="0.05"><g class="pop"><circle class="dot" r="7"/><text class="wp-label" x="-20" y="1" text-anchor="end">Depart</text><text class="wp-sub" x="-20" y="17" text-anchor="end">km 0 — trailhead</text></g></g>
+ <g class="wp" data-f="0.27"><g class="pop"><circle class="dot" r="7"/><text class="wp-label" x="20" y="1">River crossing</text><text class="wp-sub" x="20" y="17">km 12 — footbridge</text></g></g>
+ <g class="wp" data-f="0.50"><g class="pop"><circle class="dot" r="7"/><text class="wp-label" x="20" y="1">Basecamp</text><text class="wp-sub" x="20" y="17">km 27 — overnight</text></g></g>
+ <g class="wp" data-f="0.73"><g class="pop"><circle class="dot" r="7"/><text class="wp-label" x="-20" y="1" text-anchor="end">Summit ridge</text><text class="wp-sub" x="-20" y="17" text-anchor="end">km 39 — 2 410 m</text></g></g>
+ <g class="wp" data-f="0.95"><g class="pop"><circle class="dot" r="7"/><text class="wp-label" x="20" y="1">Arrive</text><text class="wp-sub" x="20" y="17">km 46 — journey's end</text></g></g>
+ </g>
+ </svg>
+ <div class="scene-cap">— end of route —</div>
+ </div>
+ </div>
+ <div class="hb-player">
+ <button class="hb-play" type="button" id="btn-scroll" data-hb-autoscroll><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M19 12l-7 7-7-7"/></svg>Play</button>
+ <button class="hb-play" type="button" id="btn-top" data-hb-top><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 19V5M5 12l7-7 7 7"/></svg>Back to top</button>
</div>
- </div>
+ </section>
- <aside>
- <p class="note">The path is part of the page, not a pinned scene. <code>stroke-dasharray</code> is set to the path's length once; each scroll frame writes <code>stroke-dashoffset&nbsp;=&nbsp;length&nbsp;−&nbsp;drawn</code>, revealing exactly as much of the route as you have travelled.</p>
- <div><div class="lbl">Progress</div>
- <div class="tbl">
- <div class="kv"><span>Scroll</span><span class="v" id="scroll-kv">0%</span></div>
- <div class="kv"><span>Path drawn</span><span class="v" id="drawn-kv">0%</span></div>
- <div class="kv"><span>Waypoints passed</span><span class="v" id="wp-kv">0 / 5</span></div>
+ <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, then scroll again or press Play.</p></div>
+ </div>
+ <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="linear" class="on" aria-pressed="true">Even</button>
+ <button type="button" data-ease="out" aria-pressed="false">Smooth</button>
+ </div>
+ <p class="hb-hint">Even keeps the tip with your scroll; Smooth runs ahead.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-switch-row"><span>Shows the stops</span><input class="hb-switch" type="checkbox" role="switch" id="wp-tog" checked autocomplete="off"></label>
+ <p class="hb-hint">Labelled points pop in as the line reaches them.</p>
</div>
</div>
- <div class="div"></div>
- <div><div class="lbl" id="ca-lbl">Line completes at</div>
- <div class="sr"><input type="range" id="ca-sl" aria-labelledby="ca-lbl" min="60" max="100" value="85"><span class="sv" id="ca-val">85%</span></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="finish-lbl">Line finishes</p>
+ <div class="seg" id="finish-seg" role="group" aria-labelledby="finish-lbl">
+ <button type="button" data-at="0.7" aria-pressed="false">Early</button>
+ <button type="button" data-at="0.85" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-at="1" aria-pressed="false">At the end</button>
+ </div>
+ <p class="hb-hint">Early leaves the whole route on show for a while.</p>
+ </div>
+ </div>
+ </details>
+ </section>
+
+ <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><div class="lbl" id="ease-lbl">Easing</div>
- <select id="ease-sel" aria-labelledby="ease-lbl">
- <option value="linear">linear — 1:1 with scroll</option>
- <option value="out">ease out — fast start</option>
- </select>
+ <div class="hb-card">
+ <p class="hb-prompt">Add a scroll-drawn route to [your timeline, journey or process steps]. Draw a long winding path down the page with a faint dashed copy underneath, and reveal the solid line in step with the scroll so its tip travels down with the visitor. Measure the path's length once and reveal it by sliding a single dash that is exactly as long as the path. When the settings include them, place labelled stops along the path and pop each one in as the line reaches it; scrolling back up erases the line and hides them again. If the visitor has reduced motion turned on, show each stop without the pop. 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>
+
+ <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>
- <label class="chk"><input type="checkbox" id="wp-chk" checked> Waypoints</label>
- </aside>
-</div>
+ <div class="hb-fit">
+ <h2>Good for</h2>
+ <ul class="hb-tags hb-good"><li>Timelines</li><li>Journey maps</li><li>Process steps</li><li>Delivery tracking</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Short pages</li></ul>
+ </div>
+ </section>
+ <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 $=id=>document.getElementById(id);
- const stage=$('stage'),trail=$('trail'),map=$('map');
- const scrollKv=$('scroll-kv'),drawnKv=$('drawn-kv'),wpKv=$('wp-kv');
- const caSl=$('ca-sl'),caVal=$('ca-val'),easeSel=$('ease-sel'),wpChk=$('wp-chk');
+ const stage=document.getElementById('stage'),trail=document.getElementById('trail'),map=document.getElementById('map');
+ const wpTog=document.getElementById('wp-tog');
const clamp=(v,a,b)=>Math.min(Math.max(v,a),b);
const EASES={linear:t=>t,out:t=>1-Math.pow(1-t,3)};
@@ -152,49 +169,59 @@ body{padding-top:46px}
// just LEN * fraction — no per-scroll geometry lookups ever.
const wps=[...document.querySelectorAll('.wp')].map(g=>({g,f:parseFloat(g.dataset.f),len:0,on:false}));
- // Layout reads live here only — at init and on (debounced) resize, never per scroll.
- let LEN=1,MAXS=1;
+ let easeMode='linear',completeAt=0.85;
+
+ // Layout reads live here only — at init, after the fonts load and on resize, never per scroll.
+ // k is how many drawing units make one pixel on screen: every stop is scaled by it, so its dot and labels keep the same
+ // size on every screen while the route itself scales. One pixel less than the box scrolls: both sizes are rounded, so the
+ // true end can fall a fraction short of the measured one, and the line must still finish there.
+ let LEN=1,MAXS=1,k=1;
function measure(){
LEN=trail.getTotalLength();
- MAXS=Math.max(1,stage.scrollHeight-stage.clientHeight);
+ const width=map.getBoundingClientRect().width;
+ k=width>0?600/width:1;
+ MAXS=Math.max(1,stage.scrollHeight-stage.clientHeight-1);
trail.style.strokeDasharray=LEN;
for(const w of wps){
w.len=LEN*w.f;
const pt=trail.getPointAtLength(w.len);
- w.g.setAttribute('transform',`translate(${pt.x.toFixed(1)} ${pt.y.toFixed(1)})`);
+ w.g.setAttribute('transform',`translate(${pt.x.toFixed(1)} ${pt.y.toFixed(1)}) scale(${k.toFixed(4)})`);
}
}
- let ticking=false,lastScroll=-1,lastDrawn=-1,lastCount=-1;
+ let ticking=false;
function update(){
- const p=EASES[easeSel.value](clamp(stage.scrollTop/MAXS,0,1));
- // The line finishes before the scroll does (COMPLETE_AT < 1), so the reader sees
+ const p=EASES[easeMode](clamp(stage.scrollTop/MAXS,0,1));
+ // The line finishes before the scroll does (completeAt < 1), so the reader sees
// the route completed rather than leaving it clipped at the viewport edge.
// Clamp, don't gate: jumping to the end draws everything, back to top erases it.
- const drawn=clamp(LEN*p/(caSl.value/100),0,LEN);
+ const drawn=clamp(LEN*p/completeAt,0,LEN);
trail.style.strokeDashoffset=LEN-drawn;
- let count=0;
for(const w of wps){
const on=drawn>=w.len;
- if(on)count++;
if(on!==w.on){w.on=on;w.g.classList.toggle('on',on)} // toggle only on change
}
- const sPct=Math.round(clamp(stage.scrollTop/MAXS,0,1)*100),dPct=Math.round(drawn/LEN*100);
- if(sPct!==lastScroll){lastScroll=sPct;scrollKv.textContent=sPct+'%'}
- if(dPct!==lastDrawn){lastDrawn=dPct;drawnKv.textContent=dPct+'%'}
- if(count!==lastCount){lastCount=count;wpKv.textContent=count+' / '+wps.length}
ticking=false;
}
stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});
- caSl.addEventListener('input',()=>{caVal.textContent=caSl.value+'%';update()});
- easeSel.addEventListener('change',update);
- wpChk.addEventListener('change',()=>map.classList.toggle('no-wps',!wpChk.checked));
- let rt;addEventListener('resize',()=>{clearTimeout(rt);rt=setTimeout(()=>{measure();update()},150)});
+ // the box or the drawing changes size under the same scroll position, so measure again and draw at once
+ window.addEventListener('resize',()=>{measure();update()});
+ if(document.fonts&&document.fonts.ready)document.fonts.ready.then(()=>{measure();update()});
+
+ 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('feel-seg',d=>{easeMode=d.ease;update()});
+ choices('finish-seg',d=>{completeAt=+d.at;update()});
+ wpTog.addEventListener('change',()=>map.classList.toggle('no-wps',!wpTog.checked));
measure();update();
</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 04d3a9c6..290dd2e8 100644
--- a/index.html
+++ b/index.html
@@ -902,7 +902,7 @@ const CATS=[
['smooth-scroll','Smooth (Inertia) Scroll','Scrolling glides to a stop instead of jumping. Best for portfolio sites.'],
['text-fill-on-scroll','Text Fill on Scroll','Words light up one by one as you scroll. Best for key statements.'],
['scroll-velocity-skew','Scroll Velocity Skew','Rows lean when you scroll fast and straighten when you stop. Best for galleries.'],
- ['svg-line-draw','SVG Line Draw on Scroll','A winding route draws itself down the page via stroke-dashoffset, passing waypoints as you travel.'],
+ ['svg-line-draw','SVG Line Draw on Scroll','A line draws itself along a route as you scroll. Best for timelines.'],
['scrollspy-nav','Scrollspy Navigation','A nav rail tracks the section in view with a sliding indicator — the docs-site pattern.'],
['scroll-background-color','Scroll-Driven Background Color','The background blends between section palettes as you scroll, flipping text contrast on light stops.'],
]