176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
feat: move Scrollytelling to the guided-steps page
matinc30a185752f9
diff --git a/animations/01-scroll-based/scrollytelling/README.md b/animations/01-scroll-based/scrollytelling/README.mdindex c2cae987..212260a3 100644--- a/animations/01-scroll-based/scrollytelling/README.md+++ b/animations/01-scroll-based/scrollytelling/README.md@@ -1,7 +1,7 @@# Scrollytelling## What it is-Scrollytelling binds a narrative to the scroll position, so that advancing through text chapters continuously drives a synchronized visual. Rather than snapping between discrete states, it computes a fractional progress value and interpolates every visual property from it — the reader experiences one continuous journey, not a slideshow. This demo descends through six ocean depth zones, crossfading a porthole's water color and counting metres as you scroll.+Scrollytelling ties a picture to a story told in scrolling text. As you read down, the picture beside the text changes with you, blending smoothly between chapters instead of switching at each one. In the demo you sink through six layers of the ocean while the porthole's water darkens and the depth counts up to 10,935 metres.## When to use it- Data-driven stories where a chart, map, or diagram should evolve as the reader progresses@@ -27,21 +27,20 @@ Reads are throttled with a `requestAnimationFrame` gate (`ticking`) so the scrol## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|-| Reading line | 0.42 × stage height | Where a chapter is considered "active"; lower = triggers later |-| Chapter min-height | 0.9 × stage height | Scroll distance per chapter; taller = slower, more granular transitions |-| Fraction `cf` | derived | Drives every crossfade; 0 at chapter start, approaches 1 at the next boundary |-| rAF gate | on | Coalesces scroll events to one update per frame |+| Reading line | 42% down the box | A chapter becomes current once its top passes this line; a lower line changes chapters later |+| Chapter height | At least 90% of the box | How much scrolling each chapter takes; taller chapters make slower, finer blends |+| Number of chapters | 6 | Each chapter adds its colours and its depth to the blend |## Production notes- **Fractional, not stepped**: the value that makes scrollytelling feel smooth is the decimal progress between chapters. If you only switch on integer chapter changes, you get a slideshow — interpolate everything you can.- **Sticky visual, scrolling text**: the pattern is a `position: sticky` visual beside taller text columns. This is cheaper and more robust than JS-pinning; let CSS hold the visual in place.- **Throttle reads**: `getBoundingClientRect` in a scroll handler forces layout. The rAF gate here keeps that to once per frame; on heavier visuals, cache rects and only recompute on resize.- **Color interpolation**: blending hex colors requires parsing to RGB channels and lerping each — CSS won't tween `background` mid-value on its own, which is why this is done in JS.-- **Reduced motion**: the demo drops the porthole's `transition` under `prefers-reduced-motion`; content and depth still update, just without the eased color fade.+- **Reduced motion**: nothing here moves on its own; the colours and the depth follow the reader's scrolling, so there is nothing to switch off. A CSS transition on the porthole's gradient would not help anyway: gradients cannot be transitioned, which is why the blend is worked out in JavaScript.- **Library equivalents**: Scrollama is the standard vanilla library for the "sticky graphic + scrolling steps" layout; GSAP ScrollTrigger with `scrub` handles the interpolation; Framer Motion's `useScroll` + `useTransform` map scroll progress to any animated value in React.## See also-- [Sticky Section](../sticky-section/) — pinning a section and scrubbing through internal states-- [Scrub Animation](../scrub-animation/) — tying an animation's timeline directly to scroll-- [Reveal on Scroll](../reveal-on-scroll/) — discrete triggers instead of continuous progress-- [Progress Bar](../progress-bar/) — surfacing scroll progress as a readout+- [Sticky Section](../sticky-section/) — a whole section holds still while its content changes+- [Scrub Animation](../scrub-animation/) — scroll plays an animation forward and back+- [Reveal on Scroll](../reveal-on-scroll/) — cards appear as they cross a line+- [Progress Bar](../progress-bar/) — a bar fills as you readdiff --git a/animations/01-scroll-based/scrollytelling/index.html b/animations/01-scroll-based/scrollytelling/index.htmlindex 4af7362a..00213961 100644--- a/animations/01-scroll-based/scrollytelling/index.html+++ b/animations/01-scroll-based/scrollytelling/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Scrollytelling — Animation Handbook</title>- <meta name="description" content="Fractional chapter progress drives depth readout and ocean-layer crossfades continuously, not in steps.">+ <meta name="description" content="A picture beside the story changes as you read down. Best for data stories."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/scrollytelling/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,100 +12,111 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Scrollytelling — Animation Handbook">- <meta property="og:description" content="Fractional chapter progress drives depth readout and ocean-layer crossfades continuously, not in steps.">+ <meta property="og:description" content="A picture beside the story changes as you read down. Best for data stories."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/scrollytelling/"><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="Scrollytelling — Animation Handbook">- <meta name="twitter:description" content="Fractional chapter progress drives depth readout and ocean-layer crossfades continuously, not in steps.">+ <meta name="twitter:description" content="A picture beside the story changes as you read down. Best for data stories."><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": "Scrollytelling", "name": "Scrollytelling", "description": "Fractional chapter progress drives depth readout and ocean-layer crossfades continuously, not in steps.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/scrollytelling/", "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, Scrollytelling"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Scrollytelling", "name": "Scrollytelling", "description": "A picture beside the story changes as you read down. Best for data stories.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/scrollytelling/", "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, Scrollytelling"}</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:640px;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace}+ :root{--ui-accent:#6ea8ff;--ui-border:rgba(255,255,255,.09);--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(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);overflow-y:scroll;scrollbar-width:none;border:1px solid var(--ui-border);border-radius:8px;display:flex}+ .stage{position:relative;overflow-y:auto;scrollbar-width:none;container-type:size;background:#0b0b0d;display:flex}.stage::-webkit-scrollbar{display:none}- .vis{position:sticky;top:0;width:45%;height:var(--stage-h);flex-shrink:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:20px;padding:28px;overflow:hidden}+ .vis{position:sticky;top:0;width:45%;height:100cqh;flex-shrink:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:20px;padding:28px;overflow:hidden}.chapters{flex:1;padding:20px 28px}- .ch{min-height:calc(var(--stage-h) * 0.9);display:flex;flex-direction:column;justify-content:center;padding:40px 0;border-bottom:1px solid var(--ui-border)}+ .ch{min-height:90cqh;display:flex;flex-direction:column;justify-content:center;padding:40px 0;border-bottom:1px solid var(--ui-border)}.ch:last-child{border-bottom:none}- .ch-eye{font-size:10px;text-transform:uppercase;letter-spacing:2px;margin-bottom:8px;opacity:.6}+ .ch-eye{font-size:11px;text-transform:uppercase;letter-spacing:2px;margin-bottom:8px}.ch-head{font-size:clamp(18px,2.6vw,26px);font-weight:bold;line-height:1.2;margin-bottom:14px}- .ch-body{font-size:12px;line-height:1.7;opacity:.65;max-width:300px;margin-bottom:12px}- .ch-fact{border-left:3px solid var(--ui-accent);padding-left:12px;font-size:10px;opacity:.5;font-style:italic;line-height:1.6}- #porthole{width:min(220px,85%);aspect-ratio:1;border-radius:50%;border:4px solid #00c8ff;overflow:hidden;flex-shrink:0;position:relative}- #ph-bg{position:absolute;inset:0;transition:background 1.2s ease}+ .ch-body{font-size:14px;line-height:1.7;opacity:.65;max-width:300px;margin-bottom:12px}+ .ch-fact{border-left:3px solid var(--ui-accent);padding-left:12px;font-size:14px;opacity:.5;line-height:1.6}+ /* The porthole shrinks in short boxes so it and the depth under it fit the column */+ #porthole{width:min(220px,85%,calc(100cqh - 106px));aspect-ratio:1;border-radius:50%;border:4px solid #00c8ff;overflow:hidden;flex-shrink:0;position:relative}+ #ph-bg{position:absolute;inset:0}#ph-shimmer{position:absolute;inset:0;background:linear-gradient(145deg,rgba(255,255,255,.06) 0%,transparent 50%)}#depth-num{font-size:clamp(26px,3.5vw,42px);font-weight:bold;letter-spacing:2px;font-variant-numeric:tabular-nums;text-align:center}- #depth-lbl{font-size:10px;opacity:.4;letter-spacing:3px;text-transform:uppercase;text-align:center}- aside{width:clamp(180px,20vw,220px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:14px;display:flex;flex-direction:column;gap:9px}- .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)}- .jlist{display:flex;flex-direction:column;gap:3px}- .jbtn{background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:6px 8px;border-radius:4px;cursor:pointer;text-align:left;min-height:36px;width:100%}- .jbtn.on{border-color:var(--ui-accent);color:var(--ui-accent)}- @media(hover:hover){.jbtn:hover{border-color:var(--ui-accent)}}- 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%}- @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}+ #depth-lbl{font-size:11px;color:var(--ui-muted);letter-spacing:3px;text-transform:uppercase;text-align:center}+ /* Phones: the porthole and the depth become a strip across the top and the chapters scroll under it */@media(max-width:600px){- .layout{flex-direction:column}aside{width:100%}.stage{flex:none;width:100%}:root{--stage-h:560px}- .stage{flex-direction:column}.vis{position:sticky;top:0;width:100%;height:200px;flex-direction:row;gap:16px;z-index:2}- #porthole{width:140px}.chapters{padding:12px 16px}+ .stage{flex-direction:column}+ .vis{position:sticky;top:0;width:100%;height:112px;flex-direction:row;gap:16px;padding:14px 16px;z-index:2;background:#0b0b0d}+ #porthole{width:84px;border-width:3px}+ .chapters{padding:12px 16px}}- @media(prefers-reduced-motion:reduce){#ph-bg{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="../snap-scrolling/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../reveal-on-scroll/" 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/scrollytelling/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>-<header>- <h1>Scrollytelling</h1>- <p>Fractional chapter progress drives depth readout and ocean-layer crossfades continuously, not in steps.</p>-</header>-<div class="layout">- <div class="stage" id="stage">- <div class="vis" id="vis">- <div id="porthole"><div id="ph-bg"></div><div id="ph-shimmer"></div></div>- <div><div id="depth-num">0</div><div id="depth-lbl">metres depth</div></div>+<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="../snap-scrolling/" rel="prev" aria-label="Previous: Snap Scrolling"><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>Snap Scrolling</span></a><a href="../reveal-on-scroll/" rel="next" aria-label="Next: Reveal on Scroll"><span><span class="hb-dir">Next: </span>Reveal on Scroll</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.11 · Scroll-Based</p>+ <h1>Scrollytelling</h1>+ <p class="hb-lede">A picture beside the story changes as you read down. Best for data stories.</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="Six chapters about the ocean's depths">+ <div class="vis">+ <div id="porthole" aria-hidden="true"><div id="ph-bg"></div><div id="ph-shimmer"></div></div>+ <div><div id="depth-num" role="img" aria-label="0 metres deep">0</div><div id="depth-lbl" aria-hidden="true">metres depth</div></div>+ </div>+ <div class="chapters" id="chapters"></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>+ </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 scrollytelling layout to [your story and the picture that goes with it]. Put the story in a column of chapters that scrolls, and keep the picture in view beside it. Work out which chapter has passed a reading line about 40% down the view and how far it is toward the next, as a fraction, and blend every value in the picture between the two chapters with it, such as colors and a counting number, so the picture changes smoothly as the visitor reads. On phones, pin a short strip of the picture above the text. If the visitor has reduced motion turned on, change the picture 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 story and picture.</p>+ </div></div>- <div class="chapters" id="chapters"></div>- </div>- <aside>- <p class="note">Scrollytelling synchronizes multiple media types to a single scroll input. Fractional progress drives smooth transitions — the reader experiences a continuous journey, not a slideshow.</p>- <div class="lbl">Position</div>- <div class="kv"><span>Scroll</span><span class="v" id="sc-pct">0%</span></div>- <div class="kv"><span>Chapter</span><span class="v" id="sc-ch">—</span></div>- <div class="div"></div>- <div class="lbl">Jump to chapter</div>- <div class="jlist" id="jlist"></div>- <div class="div"></div>- <button class="rst" id="rst">Return to surface</button>- </aside>-</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>Data stories</li><li>Explainers</li><li>Long reads</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Short pages</li><li>Quick reference</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 CHS=[{depth:0, head:'The Surface', eye:'01 · 0 m', bg:'#1a4a8c',ac:'#40d8ff',@@ -129,7 +140,7 @@ body{padding-top:46px}];const stage=document.getElementById('stage'),chs=document.getElementById('chapters');const phBg=document.getElementById('ph-bg'),porthole=document.getElementById('porthole');- const depNum=document.getElementById('depth-num'),vis=document.getElementById('vis');+ const depNum=document.getElementById('depth-num');let ticking=false;function lerpCol(h1,h2,t){@@ -139,45 +150,42 @@ body{padding-top:46px}}const clamp=(v,a,b)=>Math.min(Math.max(v,a),b),lerp=(a,b,t)=>a+(b-a)*t;- CHS.forEach((c,i)=>{+ // The three deepest colours are nearly invisible on the dark stage, so a label uses its chapter colour mixed half and half with the text colour+ CHS.forEach(c=>{const d=document.createElement('div');d.className='ch';- d.innerHTML=`<div class="ch-eye" style="color:${c.ac}">${c.eye}</div>+ d.innerHTML=`<div class="ch-eye" style="color:${lerpCol(c.ac,'#f4f4f2',0.5)}">${c.eye}</div><div class="ch-head">${c.head}</div><div class="ch-body">${c.body}</div><div class="ch-fact">${c.fact}</div>`;chs.appendChild(d);- const b=document.createElement('button');b.className='jbtn';b.textContent=c.eye;- b.addEventListener('click',()=>stage.scrollTo({top:chs.children[i].offsetTop,behavior:'smooth'}));- document.getElementById('jlist').appendChild(b);});function update(){- const st=stage.scrollTop,max=stage.scrollHeight-stage.clientHeight;- document.getElementById('sc-pct').textContent=max>0?Math.round(st/max*100)+'%':'0%';- const els=[...chs.children],N=els.length,sr=stage.getBoundingClientRect();- let frac=0;- for(let i=N-1;i>=0;i--){- const r=els[i].getBoundingClientRect();- const rel=r.top-sr.top;- if(rel<=sr.height*0.42){frac=clamp(i+(-rel/r.height),i,i+1);break;}- if(i===0)frac=0;- }+ const els=[...chs.children],N=els.length,st=stage.scrollTop,line=stage.clientHeight*0.42;+ // Where the scrolled content starts, measured from the box's own edge inside its border+ const origin=stage.getBoundingClientRect().top+stage.clientTop-st;+ // The scroll position at which each chapter's top reaches the reading line; the first chapter is current from the start+ const reach=els.map((el,i)=>i?el.getBoundingClientRect().top-origin-line:0);+ let cur=N-1;while(cur>0&&st<reach[cur])cur--;+ // The last chapter to cross the line, and how far the line has travelled from its top toward the next chapter's top+ let frac=cur<N-1?cur+(st-reach[cur])/(reach[cur+1]-reach[cur]):cur;frac=clamp(frac,0,N-0.001);const ci=Math.floor(frac),cf=frac-ci;const c=CHS[ci],cn=CHS[Math.min(ci+1,N-1)];const col=lerpCol(c.ac,cn.ac,cf);depNum.textContent=Math.round(lerp(c.depth,cn.depth,cf)).toLocaleString();- depNum.style.color=col;+ depNum.setAttribute('aria-label',depNum.textContent+(depNum.textContent==='1'?' metre deep':' metres deep'));+ depNum.style.color=lerpCol(col,'#f4f4f2',0.5);phBg.style.background=`radial-gradient(circle at 50% 40%,${lerpCol(c.bg,cn.bg,cf)},#000 80%)`;porthole.style.borderColor=col;- document.getElementById('sc-ch').textContent=c.eye;- document.querySelectorAll('.jbtn').forEach((b,i)=>b.classList.toggle('on',i===ci));ticking=false;}+ function request(){if(!ticking){ticking=true;requestAnimationFrame(update)}}- stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});- document.getElementById('rst').addEventListener('click',()=>{stage.scrollTop=0;update()});+ stage.addEventListener('scroll',request,{passive:true});+ addEventListener('resize',request);update();+ // The chapters' heights depend on the site font+ if(document.fonts&&document.fonts.ready)document.fonts.ready.then(request);</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.htmlindex 9cce4308..572f5b84 100644--- a/index.html+++ b/index.html@@ -889,7 +889,7 @@ const CATS=[['scrub-animation','Scrub Animation','Scroll plays it forward and back, like dragging a video. Best for product tours.'],['pin-animation','Pin Animation','One part stays put while its text changes on scroll. Best for feature lists.'],['snap-scrolling','Snap Scrolling','The box settles on one whole section at a time. Best for slides and galleries.'],- ['scrollytelling','Scrollytelling','Fractional chapter progress drives continuous depth crossfades across six ocean-layer chapters.'],+ ['scrollytelling','Scrollytelling','A picture beside the story changes as you read down. Best for data stories.'],['reveal-on-scroll','Reveal on Scroll','Seven reveal techniques fired by IntersectionObserver at a configurable trigger line.'],['stagger-reveal','Stagger Reveal','Groups reveal with cascading delays — forward, reverse, center-out, and random cascade directions.'],['horizontal-scroll','Horizontal Scroll','Vertical scroll translates a horizontal panel strip — a tall pinned section provides the scroll budget.'],