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 Sticky Section to the guided-steps page

matinc92d1e24135a
diff --git a/animations/01-scroll-based/sticky-section/README.md b/animations/01-scroll-based/sticky-section/README.md
index 2800e103..e7ba3034 100644
--- a/animations/01-scroll-based/sticky-section/README.md
+++ b/animations/01-scroll-based/sticky-section/README.md
@@ -1,7 +1,7 @@
# Sticky Section
## What it is
-A sticky section pins an entire section to the viewport for an extended scroll distance while its interior morphs through a sequence of states. The pin is created with `position: sticky` inside a tall wrapper; scroll position within that wrapper becomes a 0–1 timeline that the contents are scrubbed against. This demo holds a two-column section in place and cycles it through four labelled states, with a segmented progress readout.
+A sticky section holds a whole section still while you scroll, and uses that scrolling to step its content through a sequence instead of moving the page. The section sits inside a tall wrapper, and how far you have scrolled through the wrapper decides which step shows, so scrolling back steps backwards. In the demo, a text column and a picture change together through four steps, then the section scrolls away.
## When to use it
- Multi-step explanations where one frame should stay put while its content advances
@@ -10,30 +10,25 @@ A sticky section pins an entire section to the viewport for an extended scroll d
- Any sequence where pinning the frame keeps the reader oriented better than scrolling new sections in
## How it works
-The wrapper is four stage-heights tall; the inner section is `position: sticky; top: 0`, so it stays fixed while the wrapper scrolls past. Progress is `(scrollTop − pinStart) / (pinHeight − stageHeight)`, clamped to 0–1. Multiplying by the state count gives the active state index and the fraction within it:
+The wrapper is four stage-heights tall; the inner section is `position: sticky; top: 0`, so it stays fixed while the wrapper scrolls past. Progress is `(scrollTop − pinStart) / (pinHeight − stageHeight)`, clamped to 0–1. Multiplying by the state count gives the active state index:
```js
const pinStart = wrap.offsetTop, pinH = wrap.offsetHeight;
const p = clamp((st - pinStart) / (pinH - stageH), 0, 1); // 0..1 while pinned
-const si = Math.min(Math.floor(p * 4), 3), sf = p * 4 - si; // state index + fraction
+const si = Math.min(Math.floor(p * 4), 3); // state index
states.forEach((s, i) => s.classList.toggle('visible', i === si));
illus.forEach((il, i) => il.classList.toggle('visible', i === si));
-for (let i = 0; i < 4; i++) { // segmented progress
- const bar = document.getElementById('sg' + i);
- bar.style.width = i < si ? '100%' : i === si ? Math.round(sf * 100) + '%' : '0%';
-}
```
-The three lifecycle phases — `approaching`, `stuck`, `released` — come from comparing `scrollTop` against the pin's start and end. States themselves crossfade via a CSS `opacity` transition on `.visible`; only the segment bars use the raw fraction, so the section reads as pinned frames advancing rather than a continuous scrub.
+States crossfade via a CSS `opacity` transition on `.visible`, so the section reads as pinned frames advancing rather than a continuous scrub.
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Wrapper height | 4 × stage height | Total scroll budget; more height = slower state changes |
-| State count | 4 | `p × count` maps progress to states; each owns `1 / count` of the range |
-| Progress `p` | derived | 0 at pin start, 1 when the pin releases |
-| State transition | 0.5s opacity | Crossfade between states; illustration column uses 0.6s |
+| Number of steps | 4 | Each step owns an equal share of the scrolling while the section holds still |
+| Wrapper height | Four box heights | The section holds still for three of them; a taller wrapper makes each step last longer |
+| Fade between steps | 0.5 s | How long the text takes to fade to the next step; the picture takes 0.6 s |
## Production notes
- **Pins the section, not one element**: this is the key distinction from pin-animation. Here the whole section sticks and its *contents* change; a pin-animation pins one element while siblings scroll past it.
@@ -44,7 +39,7 @@ The three lifecycle phases — `approaching`, `stuck`, `released` — come from
- **Library equivalents**: GSAP ScrollTrigger with `pin: true` and a `scrub` timeline is the production-grade version and adds easing across states; Framer Motion pairs a sticky wrapper with `useScroll({ offset })` to derive the same progress value.
## See also
-- [Pin Animation](../pin-animation/) — pinning a single element while siblings pass
-- [Scrub Animation](../scrub-animation/) — tying a timeline continuously to scroll
-- [Scrollytelling](../scrollytelling/) — a sticky visual driven by scrolling narrative
-- [Section Wipe](../section-wipe/) — stacked sticky sections that cover one another
+- [Pin Animation](../pin-animation/) — one element holds still while the rest scrolls past
+- [Scrub Animation](../scrub-animation/) — scrolling moves a plane along its path, both ways
+- [Scrollytelling](../scrollytelling/) — a picture beside the text changes as a story scrolls by
+- [Section Wipe](../section-wipe/) — each section slides up over the one before
diff --git a/animations/01-scroll-based/sticky-section/index.html b/animations/01-scroll-based/sticky-section/index.html
index 28960702..c04e9d42 100644
--- a/animations/01-scroll-based/sticky-section/index.html
+++ b/animations/01-scroll-based/sticky-section/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sticky Section — Animation Handbook</title>
- <meta name="description" content="The whole section pins to the viewport while its interior morphs through 4 states — scrubbed to scroll position.">
+ <meta name="description" content="A section holds still while its content changes. Best for feature tours.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/sticky-section/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,202 +12,190 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Sticky Section — Animation Handbook">
- <meta property="og:description" content="The whole section pins to the viewport while its interior morphs through 4 states — scrubbed to scroll position.">
+ <meta property="og:description" content="A section holds still while its content changes. Best for feature tours.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/sticky-section/">
<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="Sticky Section — Animation Handbook">
- <meta name="twitter:description" content="The whole section pins to the viewport while its interior morphs through 4 states — scrubbed to scroll position.">
+ <meta name="twitter:description" content="A section holds still while its content changes. Best for feature tours.">
<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": "Sticky Section", "name": "Sticky Section", "description": "The whole section pins to the viewport while its interior morphs through 4 states — scrubbed to scroll position.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/sticky-section/", "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, Sticky Section"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Sticky Section", "name": "Sticky Section", "description": "A section holds still while its content changes. Best for feature tours.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/sticky-section/", "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, Sticky Section"}</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;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px}
+ :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-accent:#6ea8ff}
*,*::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}
+ /* 100cqh is one stage height: the stage is the size container, so the pinned frame is exactly one box tall at every size */
+ .stage{position:relative;overflow-y:auto;scrollbar-width:none;container-type:size;background:#0b0b0d}
.stage::-webkit-scrollbar{display:none}
- .spacer{height:var(--stage-h);display:flex;align-items:center;justify-content:center;font-size:11px;opacity:.25;letter-spacing:2px;text-align:center;padding:20px}
- /* Sticky section — 4× stage height for scroll budget */
- #sticky-wrap{height:calc(var(--stage-h) * 4);position:relative}
- #sticky-inner{position:sticky;top:0;height:var(--stage-h);overflow:hidden;display:grid;grid-template-columns:1fr 1fr;gap:0}
+ /* Lead-in and lead-out */
+ .spacer{height:100cqh;display:flex;align-items:center;justify-content:center;padding:0 24px;font-size:13px;color:#8a8a92;letter-spacing:.1em;text-align:center}
+ /* Sticky section: four box heights of scrolling, three of them with the frame held still */
+ #sticky-wrap{height:400cqh;position:relative}
+ #sticky-inner{position:sticky;top:0;height:100cqh;overflow:hidden;display:grid;grid-template-columns:1fr 1fr;gap:0}
/* States */
- .state{position:absolute;inset:0;display:flex;flex-direction:column;justify-content:center;padding:clamp(24px,4vw,48px);opacity:0;pointer-events:none;transition:opacity .5s ease}
+ .state{position:absolute;inset:0;display:flex;flex-direction:column;justify-content:center;padding:clamp(24px,4vw,40px);opacity:0;pointer-events:none;transition:opacity .5s ease}
.state.visible{opacity:1;pointer-events:auto}
- .state-eye{font-size:10px;text-transform:uppercase;letter-spacing:2px;margin-bottom:12px;opacity:.6}
- .state-head{font-size:clamp(20px,3vw,32px);font-weight:bold;line-height:1.2;margin-bottom:16px}
- .state-body{font-size:12px;opacity:.6;line-height:1.7;max-width:340px}
- .state-cta{margin-top:20px;align-self:flex-start;border:1px solid var(--ui-accent);color:var(--ui-accent);font-family:var(--mono);font-size:10px;padding:10px 16px;border-radius:4px;letter-spacing:1px}
+ .state-eye{font-size:12px;font-weight:600;text-transform:uppercase;letter-spacing:2px;margin-bottom:12px}
+ .state-head{font-size:clamp(20px,2.6vw,28px);font-weight:700;line-height:1.2;margin-bottom:16px}
+ .state-body{font-size:15px;line-height:1.6;color:#adadb2;max-width:340px}
/* Visual column */
- #vis-col{position:sticky;top:0;height:var(--stage-h);background:var(--ui-bg);display:flex;align-items:center;justify-content:center;overflow:hidden}
+ #vis-col{position:sticky;top:0;height:100cqh;background:var(--ui-bg);display:flex;align-items:center;justify-content:center;overflow:hidden}
.illus{position:absolute;width:min(280px,80%);aspect-ratio:1;opacity:0;transition:opacity .6s ease;display:flex;align-items:center;justify-content:center}
.illus.visible{opacity:1}
/* Text column */
- #text-col{position:relative;height:var(--stage-h);background:var(--bg)}
- /* Progress bar */
- #seg-bar{display:flex;gap:3px;margin-top:8px}
- .seg-fill{flex:1;height:4px;border-radius:2px;background:var(--ui-border);overflow:hidden}
- .seg-inner{height:100%;background:var(--ui-accent);width:0%;transition:width .1s}
- 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)}
- 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}aside{width:100%}:root{--stage-h:480px}#sticky-inner{grid-template-columns:1fr}#vis-col{display:none}}
+ #text-col{position:relative;height:100cqh;background:var(--bg)}
+ @media(max-width:600px){#sticky-inner{grid-template-columns:1fr}#vis-col{display:none}}
@media(prefers-reduced-motion:reduce){.state,.illus{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=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="../horizontal-scroll/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../counter-animation/" 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/sticky-section/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-<header>
- <h1>Sticky Section</h1>
- <p>The whole section pins to the viewport while its interior morphs through 4 states — scrubbed to scroll position.</p>
-</header>
-<div class="layout">
- <div class="stage" id="stage">
- <div class="spacer">Scroll down to enter the sticky section ↓</div>
- <div id="sticky-wrap">
- <div id="sticky-inner">
- <div id="text-col">
- <div class="state" id="s0">
- <div class="state-eye" style="color:#79c0ff">State 01 · Foundation</div>
- <div class="state-head">Everything starts with structure.</div>
- <div class="state-body">Before any animation, there is layout. CSS sticky positioning transforms a single section into an extended viewport experience without JavaScript pinning.</div>
- </div>
- <div class="state" id="s1">
- <div class="state-eye" style="color:#56d364">State 02 · Transition</div>
- <div class="state-head">Scroll becomes the timeline.</div>
- <div class="state-body">Progress through the sticky section is computed as a 0–1 value. Each state occupies 25% of that range. State boundaries are thresholds, not events.</div>
- </div>
- <div class="state" id="s2">
- <div class="state-eye" style="color:#ffa657">State 03 · Interpolation</div>
- <div class="state-head">Between states, values blend.</div>
- <div class="state-body">Crossfades between opacity values, illustration swaps, and text transitions happen in the fractional space between integer state indices — smooth, not stepped.</div>
- </div>
- <div class="state" id="s3">
- <div class="state-eye" style="color:#d2a8ff">State 04 · Release</div>
- <div class="state-head">When the budget runs out, scroll continues.</div>
- <div class="state-body">The sticky wrapper ends and the section scrolls away. Content after it resumes normal flow. The pin is defined entirely by the wrapper's height.</div>
- <div class="state-cta">Continue scrolling →</div>
- </div>
- </div>
- <div id="vis-col">
- <div class="illus" id="il0">
- <svg viewBox="0 0 200 200" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
- <rect x="30" y="30" width="140" height="140" rx="12" fill="none" stroke="#79c0ff" stroke-width="2" opacity=".4"/>
- <rect x="55" y="55" width="90" height="90" rx="8" fill="none" stroke="#79c0ff" stroke-width="2" opacity=".6"/>
- <rect x="80" y="80" width="40" height="40" rx="4" fill="#79c0ff" opacity=".3"/>
- <circle cx="100" cy="100" r="8" fill="#79c0ff"/>
- </svg>
- </div>
- <div class="illus" id="il1">
- <svg viewBox="0 0 200 200" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
- <line x1="100" y1="20" x2="100" y2="180" stroke="#56d364" stroke-width="2" opacity=".4"/>
- <line x1="20" y1="100" x2="180" y2="100" stroke="#56d364" stroke-width="2" opacity=".4"/>
- <circle cx="100" cy="40" r="12" fill="#56d364" opacity=".6"/>
- <circle cx="160" cy="100" r="12" fill="#56d364" opacity=".5"/>
- <circle cx="100" cy="160" r="12" fill="#56d364" opacity=".4"/>
- <circle cx="40" cy="100" r="12" fill="#56d364" opacity=".3"/>
- <circle cx="100" cy="100" r="6" fill="#56d364"/>
- </svg>
- </div>
- <div class="illus" id="il2">
- <svg viewBox="0 0 200 200" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
- <polygon points="100,20 180,170 20,170" fill="none" stroke="#ffa657" stroke-width="2" opacity=".5"/>
- <polygon points="100,55 155,155 45,155" fill="none" stroke="#ffa657" stroke-width="2" opacity=".5"/>
- <polygon points="100,90 130,140 70,140" fill="#ffa657" opacity=".2"/>
- <circle cx="100" cy="110" r="6" fill="#ffa657"/>
- </svg>
+<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="../horizontal-scroll/" rel="prev" aria-label="Previous: Horizontal Scroll"><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>Horizontal Scroll</span></a><a href="../counter-animation/" rel="next" aria-label="Next: Counter Animation"><span><span class="hb-dir">Next: </span>Counter Animation</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.15 · Scroll-Based</p>
+ <h1>Sticky Section</h1>
+ <p class="hb-lede">A section holds still while its content changes. Best for feature tours.</p>
+ </header>
+
+ <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 section that holds still while its content changes">
+ <p class="spacer">Scroll down ↓</p>
+ <div id="sticky-wrap">
+ <div id="sticky-inner">
+ <div id="text-col">
+ <div class="state">
+ <p class="state-eye" style="color:#79c0ff">Step 01 · Hold</p>
+ <h3 class="state-head">The section stays put.</h3>
+ <p class="state-body">Once it reaches the top of the box, the whole section stops moving while you keep scrolling.</p>
+ </div>
+ <div class="state">
+ <p class="state-eye" style="color:#56d364">Step 02 · Change</p>
+ <h3 class="state-head">Scrolling changes what is inside.</h3>
+ <p class="state-body">Each stretch of scrolling swaps the words and the picture for the next step, instead of moving the page.</p>
+ </div>
+ <div class="state">
+ <p class="state-eye" style="color:#ffa657">Step 03 · Fade</p>
+ <h3 class="state-head">Each step fades into the next.</h3>
+ <p class="state-body">The change is a quick fade, so the section reads as one frame stepping forward.</p>
+ </div>
+ <div class="state">
+ <p class="state-eye" style="color:#d2a8ff">Step 04 · Release</p>
+ <h3 class="state-head">Then the page moves on.</h3>
+ <p class="state-body">After the last step, the section scrolls away and the page carries on as normal.</p>
+ </div>
</div>
- <div class="illus" id="il3">
- <svg viewBox="0 0 200 200" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
- <circle cx="100" cy="100" r="70" fill="none" stroke="#d2a8ff" stroke-width="2" opacity=".3"/>
- <circle cx="100" cy="100" r="50" fill="none" stroke="#d2a8ff" stroke-width="2" opacity=".4"/>
- <circle cx="100" cy="100" r="30" fill="none" stroke="#d2a8ff" stroke-width="2" opacity=".6"/>
- <circle cx="100" cy="100" r="8" fill="#d2a8ff" opacity=".8"/>
- </svg>
+ <div id="vis-col">
+ <div class="illus">
+ <svg viewBox="0 0 200 200" width="200" height="200" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
+ <rect x="30" y="30" width="140" height="140" rx="12" fill="none" stroke="#79c0ff" stroke-width="2" opacity=".4"/>
+ <rect x="55" y="55" width="90" height="90" rx="8" fill="none" stroke="#79c0ff" stroke-width="2" opacity=".6"/>
+ <rect x="80" y="80" width="40" height="40" rx="4" fill="#79c0ff" opacity=".3"/>
+ <circle cx="100" cy="100" r="8" fill="#79c0ff"/>
+ </svg>
+ </div>
+ <div class="illus">
+ <svg viewBox="0 0 200 200" width="200" height="200" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
+ <line x1="100" y1="20" x2="100" y2="180" stroke="#56d364" stroke-width="2" opacity=".4"/>
+ <line x1="20" y1="100" x2="180" y2="100" stroke="#56d364" stroke-width="2" opacity=".4"/>
+ <circle cx="100" cy="40" r="12" fill="#56d364" opacity=".6"/>
+ <circle cx="160" cy="100" r="12" fill="#56d364" opacity=".5"/>
+ <circle cx="100" cy="160" r="12" fill="#56d364" opacity=".4"/>
+ <circle cx="40" cy="100" r="12" fill="#56d364" opacity=".3"/>
+ <circle cx="100" cy="100" r="6" fill="#56d364"/>
+ </svg>
+ </div>
+ <div class="illus">
+ <svg viewBox="0 0 200 200" width="200" height="200" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
+ <polygon points="100,20 180,170 20,170" fill="none" stroke="#ffa657" stroke-width="2" opacity=".5"/>
+ <polygon points="100,55 155,155 45,155" fill="none" stroke="#ffa657" stroke-width="2" opacity=".5"/>
+ <polygon points="100,90 130,140 70,140" fill="#ffa657" opacity=".2"/>
+ <circle cx="100" cy="110" r="6" fill="#ffa657"/>
+ </svg>
+ </div>
+ <div class="illus">
+ <svg viewBox="0 0 200 200" width="200" height="200" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
+ <circle cx="100" cy="100" r="70" fill="none" stroke="#d2a8ff" stroke-width="2" opacity=".3"/>
+ <circle cx="100" cy="100" r="50" fill="none" stroke="#d2a8ff" stroke-width="2" opacity=".4"/>
+ <circle cx="100" cy="100" r="30" fill="none" stroke="#d2a8ff" stroke-width="2" opacity=".6"/>
+ <circle cx="100" cy="100" r="8" fill="#d2a8ff" opacity=".8"/>
+ </svg>
+ </div>
</div>
</div>
</div>
+ <p class="spacer">The page moves on ↓</p>
</div>
- <div class="spacer">Released — normal scroll resumes ↓</div>
- </div>
- <aside>
- <p class="note">Sticky section pins the whole section, not a single element. Contents morph through states. Distinct from pin-animation, which pins one element while siblings scroll past.</p>
- <div class="lbl">Scroll state</div>
- <div class="kv"><span>Overall</span><span class="v" id="ov-pct">0%</span></div>
- <div class="kv"><span>Lifecycle</span><span class="v" id="lifecycle">approaching</span></div>
- <div class="kv"><span>State</span><span class="v" id="state-id">—</span></div>
- <div class="kv"><span>Internal</span><span class="v" id="int-pct">—</span></div>
- <div class="div"></div>
- <div class="lbl">State segments</div>
- <div id="seg-bar">
- <div class="seg-fill"><div class="seg-inner" id="sg0"></div></div>
- <div class="seg-fill"><div class="seg-inner" id="sg1"></div></div>
- <div class="seg-fill"><div class="seg-inner" id="sg2"></div></div>
- <div class="seg-fill"><div class="seg-inner" id="sg3"></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 class="div"></div>
- <button class="rst" id="rst">Reset scroll</button>
- </aside>
-</div>
+ </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">2</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 sticky section to [the steps or features you want to walk through]. Make the section several screens tall and pin its inner frame to the top of the screen while the visitor scrolls through it. Split that scroll distance into equal parts, one per step, and as each part is reached, fade the text and the picture over to the next step while the frame itself stays still. After the last step, let the section scroll away so the page carries on. Work out the step from the scroll position, so scrolling back up steps backwards. If the visitor has reduced motion turned on, switch the steps without fading.</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 steps.</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>
+ <div class="hb-fit">
+ <h2>Good for</h2>
+ <ul class="hb-tags hb-good"><li>Feature tours</li><li>How-it-works steps</li><li>Product pages</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Long text</li><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 stage=document.getElementById('stage'),wrap=document.getElementById('sticky-wrap');
const states=[...document.querySelectorAll('.state')],illus=[...document.querySelectorAll('.illus')];
- const lifecycle=document.getElementById('lifecycle'),stateId=document.getElementById('state-id');
- const intPct=document.getElementById('int-pct'),ovPct=document.getElementById('ov-pct');
- const STATE_NAMES=['Foundation','Transition','Interpolation','Release'];
let ticking=false;
const clamp=(v,a,b)=>Math.min(Math.max(v,a),b);
function update(){
- const st=stage.scrollTop,max=stage.scrollHeight-stage.clientHeight,stageH=stage.clientHeight;
- ovPct.textContent=max>0?Math.round(st/max*100)+'%':'0%';
+ const st=stage.scrollTop,stageH=stage.clientHeight;
const pinStart=wrap.offsetTop,pinH=wrap.offsetHeight;
const p=clamp((st-pinStart)/(pinH-stageH),0,1);
- const before=st<pinStart,after=st>pinStart+pinH-stageH;
- lifecycle.textContent=before?'approaching':after?'released':`stuck · ${Math.round(p*100)}%`;
- intPct.textContent=before||after?'—':Math.round(p*100)+'%';
- const si=Math.min(Math.floor(p*4),3),sf=p*4-si;
- stateId.textContent=before||after?'—':`0${si+1} · ${STATE_NAMES[si]}`;
+ const si=Math.min(Math.floor(p*4),3);
states.forEach((s,i)=>s.classList.toggle('visible',i===si));
illus.forEach((il,i)=>il.classList.toggle('visible',i===si));
- for(let i=0;i<4;i++){
- const bar=document.getElementById('sg'+i);
- if(i<si)bar.style.width='100%';
- else if(i===si)bar.style.width=Math.round(sf*100)+'%';
- else bar.style.width='0%';
- }
ticking=false;
}
+ function schedule(){if(!ticking){requestAnimationFrame(update);ticking=true}}
- stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});
- document.getElementById('rst').addEventListener('click',()=>{stage.scrollTop=0;update()});
+ stage.addEventListener('scroll',schedule,{passive:true});
+ window.addEventListener('resize',schedule);
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 f60205cc..4f3c867e 100644
--- a/index.html
+++ b/index.html
@@ -893,7 +893,7 @@ const CATS=[
['reveal-on-scroll','Reveal on Scroll','Seven reveal techniques fired by IntersectionObserver at a configurable trigger line.'],
['stagger-reveal','Stagger Reveal','Items in a group appear one after another as it scrolls in. Best for card grids.'],
['horizontal-scroll','Horizontal Scroll','Scroll down and a row of panels slides sideways. Best for portfolios.'],
- ['sticky-section','Sticky Section','The whole section pins while its interior morphs through four states scrubbed to scroll position.'],
+ ['sticky-section','Sticky Section','A section holds still while its content changes. Best for feature tours.'],
['counter-animation','Counter Animation','Numbers count 0 → target with easing on scroll entry — four formats and configurable curve.'],
['progress-bar','Progress Bar','Reading progress in three styles — top bar, circular ring, and side rail — driven by scrollTop / scrollHeight.'],
['section-wipe','Section Wipe','The next section slides over the current via sticky z-index stacking — scale-down adds depth.'],