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 Text Fill on Scroll to the guided-steps page

matind78a6989e8f3
diff --git a/animations/01-scroll-based/text-fill-on-scroll/README.md b/animations/01-scroll-based/text-fill-on-scroll/README.md
index 4c85f243..d51dcf21 100644
--- a/animations/01-scroll-based/text-fill-on-scroll/README.md
+++ b/animations/01-scroll-based/text-fill-on-scroll/README.md
@@ -4,7 +4,7 @@
## What it is
-A pinned paragraph whose words fill from dim to full color one at a time as the reader scrolls — the reading-highlight effect used on Apple- and Linear-style marketing pages. Scroll progress sweeps an index through the words: everything behind it is lit, everything ahead waits dim. Because the fill is computed from scroll position rather than played, pausing holds the sentence mid-read and scrolling back up un-reads it in perfect reverse.
+Text fill on scroll lights a paragraph up word by word as you scroll, as if it were being read at your pace. The paragraph holds still while you scroll through its section, and how far you have scrolled decides how many words are lit, so stopping holds the sentence mid-read and scrolling back un-reads it.
## When to use it
@@ -30,16 +30,15 @@ for (let i = lo; i < hi; i++) words[i].classList.toggle('on', i < filled);
lastFilled = filled;
```
-On a normal scroll step that is one or two class toggles instead of eighty, and an idle frame costs nothing. A short CSS `color` transition on each word softens the flip without fighting the per-frame logic, since the class — not the color — is what changes per frame.
+On a normal scroll step that is one or two class toggles instead of fifty, and an idle frame costs nothing. A short CSS `color` transition on each word softens the flip without fighting the per-frame logic, since the class — not the color — is what changes per frame. When a jump changes more than a quarter of the words at once (Back to top, or Play starting over), the transition is switched off for that one change, so the old state does not linger.
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Fill completes at | 90% | Portion of the scroll budget the fill is spread across; finishing early leaves a beat of read-through before the section ends |
-| Dim color | `rgba(244,244,242,.16)` | The unread state. Too faint and the text is invisible before reveal; too strong and the fill has no drama |
-| Highlight | accent | Color of the currently-active word — the "cursor" that shows where the reader is |
-| Word transition | 180ms | The soften on each word's flip; the sweep itself has no duration |
+| Highlights the current word | on | The next word to fill shows in the highlight color, like a reading cursor |
+| Fill finishes | Normal | How far through the scrolling the last word lights: early at 70%, normal at 90% and at the end at 100%; finishing early leaves a moment to read the whole text |
+| Highlight color | Blue | The color of the word being filled |
## Production notes
@@ -52,6 +51,6 @@ On a normal scroll step that is one or two class toggles instead of eighty, and
## See also
-- [Reveal on Scroll](../reveal-on-scroll/) — discrete enter/leave reveals; this entry is the continuous version for a single passage.
-- [Scrub Animation](../scrub-animation/) — the same position-not-playback model driving a drawn path.
-- [Kinetic Typography](../../05-text-typography/kinetic-typography/) — time-based type motion, for contrast with scroll-driven.
+- [Reveal on Scroll](../reveal-on-scroll/) — whole cards appear as they scroll into view; this is the continuous version for one paragraph
+- [Scrub Animation](../scrub-animation/) — scroll position drives a drawing, both ways
+- [Kinetic Typography](../../05-text-typography/kinetic-typography/) — words that each move in their own way, on a timer instead of the scroll
diff --git a/animations/01-scroll-based/text-fill-on-scroll/index.html b/animations/01-scroll-based/text-fill-on-scroll/index.html
index 2f3bea16..dca6dacc 100644
--- a/animations/01-scroll-based/text-fill-on-scroll/index.html
+++ b/animations/01-scroll-based/text-fill-on-scroll/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Fill on Scroll — Animation Handbook</title>
- <meta name="description" content="A pinned paragraph fills word by word as you scroll — the reading-highlight effect, perfectly reversible.">
+ <meta name="description" content="Words light up one by one as you scroll. Best for key statements.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/text-fill-on-scroll/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,134 +12,144 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Text Fill on Scroll — Animation Handbook">
- <meta property="og:description" content="A pinned paragraph fills word by word as you scroll — the reading-highlight effect, perfectly reversible.">
+ <meta property="og:description" content="Words light up one by one as you scroll. Best for key statements.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/text-fill-on-scroll/">
<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="Text Fill on Scroll — Animation Handbook">
- <meta name="twitter:description" content="A pinned paragraph fills word by word as you scroll — the reading-highlight effect, perfectly reversible.">
+ <meta name="twitter:description" content="Words light up one by one as you scroll. Best for key statements.">
<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": "Text Fill on Scroll", "name": "Text Fill on Scroll", "description": "A pinned paragraph fills word by word as you scroll — the reading-highlight effect, perfectly reversible.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/text-fill-on-scroll/", "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, Text Fill on Scroll"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Text Fill on Scroll", "name": "Text Fill on Scroll", "description": "Words light up one by one as you scroll. Best for key statements.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/text-fill-on-scroll/", "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, Text Fill 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;--dim:rgba(244,244,242,.16);
- --disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace}
+ :root{--ui-accent:#6ea8ff;--dim:#7c7c84}
*,*::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;container-type:size;background:#0b0b0d}
.stage::-webkit-scrollbar{display:none}
- /* .track supplies the scroll budget; .pinned holds the paragraph still while
- scroll sweeps the fill through it */
- .track{height:calc(var(--stage-h) * 3.5)}
- .pinned{position:sticky;top:0;height:var(--stage-h);display:flex;align-items:center;
- padding:clamp(18px,4vw,44px)}
- .fill-text{font-family:var(--disp);font-weight:700;font-size:clamp(19px,2.9vw,30px);
- line-height:1.5;letter-spacing:-.01em;max-width:24em}
+ /* .track supplies the scroll budget; .pinned holds the paragraph still while scroll sweeps the fill through it */
+ .track{height:350cqh}
+ .pinned{position:sticky;top:0;height:100cqh;display:flex;align-items:center;padding:clamp(18px,4vw,44px)}
+ .fill-text{font-weight:700;font-size:clamp(17px,2.4vw,24px);line-height:1.5;letter-spacing:-.01em;max-width:24em}
.fill-text .w{color:var(--dim);transition:color .18s linear}
- .fill-text .w.on{color:var(--ui-text)}
+ .fill-text .w.on{color:#f4f4f2}
.fill-text .w.cursor{color:var(--fill-accent,var(--ui-accent))}
- .hint{position:absolute;bottom:14px;left:0;right:0;text-align:center;font-size:10px;
- letter-spacing:1.5px;text-transform:uppercase;color:var(--ui-muted);opacity:.6}
-
- 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);font-variant-numeric:tabular-nums}
- .tbl{display:flex;flex-direction:column;gap:2px}
- .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}
- .swatches{display:flex;gap:8px}
- .swatch{width:44px;height:32px;border-radius:6px;border:2px solid transparent;cursor:pointer;padding:0}
- .swatch.on{border-color:var(--ui-text)}
- .tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
- .tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- .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}
- }
+ /* a big jump (Back to top, Play starting over) changes at once, so the old state does not linger */
+ .fill-text.jump .w{transition:none}
@media(prefers-reduced-motion:reduce){.fill-text .w{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="../smooth-scroll/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../scroll-velocity-skew/" 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/text-fill-on-scroll/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-<header>
- <h1>Text Fill on Scroll</h1>
- <p>A pinned paragraph fills word by word as you scroll — the reading-highlight effect, perfectly reversible.</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="../smooth-scroll/" rel="prev" aria-label="Previous: Smooth (Inertia) 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>Smooth (Inertia) Scroll</span></a><a href="../scroll-velocity-skew/" rel="next" aria-label="Next: Scroll Velocity Skew"><span><span class="hb-dir">Next: </span>Scroll Velocity Skew</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.22 · Scroll-Based</p>
+ <h1>Text Fill on Scroll</h1>
+ <p class="hb-lede">Words light up one by one as you scroll. Best for key statements.</p>
+ </header>
-<div class="layout">
- <div class="stage" id="stage">
- <div class="track">
- <div class="pinned">
- <p class="fill-text" id="fill-text"></p>
- <div class="hint">scroll to read</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 paragraph that fills word by word as you scroll">
+ <div class="track">
+ <div class="pinned">
+ <p class="fill-text" id="fill-text"></p>
+ </div>
</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>
+ </section>
- <aside>
- <p class="note">Scroll progress sweeps an index through the words: everything behind it is lit, everything ahead stays dim. Because the fill is computed from position — not played — scrolling back un-reads the paragraph exactly.</p>
- <div><div class="lbl">Progress</div>
- <div class="tbl">
- <div class="kv"><span>Scroll</span><span class="v" id="prog-kv">0%</span></div>
- <div class="kv"><span>Words filled</span><span class="v" id="words-kv">0 / 0</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">
+ <label class="hb-switch-row"><span>Highlights the current word</span><input class="hb-switch" type="checkbox" role="switch" id="cursor-tog" checked autocomplete="off"></label>
+ <p class="hb-hint">The next word to fill shows in color, like a cursor.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="finish-lbl">Fill 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.9" 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 text lit for a while.</p>
</div>
</div>
- <div class="div"></div>
- <div><div class="lbl" id="complete-lbl">Fill completes at</div>
- <div class="sr"><input type="range" id="complete-sl" aria-labelledby="complete-lbl" min="60" max="100" value="90" step="5"><span class="sv" id="complete-val">90%</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" id="color-setting">
+ <p class="hb-setting-name" id="color-lbl">Highlight color</p>
+ <div class="swatches" id="color-sw" role="group" aria-labelledby="color-lbl">
+ <button type="button" class="on" aria-pressed="true" aria-label="Blue" data-c="#6ea8ff" style="background:#6ea8ff"></button>
+ <button type="button" aria-pressed="false" aria-label="Green" data-c="#5fd88a" style="background:#5fd88a"></button>
+ <button type="button" aria-pressed="false" aria-label="Orange" data-c="#ff9d5c" style="background:#ff9d5c"></button>
+ </div>
+ <p class="hb-hint">The color of the word being filled.</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">Highlight</div>
- <div class="swatches" id="swatches">
- <button class="swatch on" style="background:#6ea8ff" data-c="#6ea8ff" aria-label="Blue highlight"></button>
- <button class="swatch" style="background:#5fd88a" data-c="#5fd88a" aria-label="Green highlight"></button>
- <button class="swatch" style="background:#ff9d5c" data-c="#ff9d5c" aria-label="Orange highlight"></button>
+ <div class="hb-card">
+ <p class="hb-prompt">Add a scroll-driven text fill to [the statement or paragraph you want read]. Pin the paragraph in place while the visitor scrolls through a section a few screens tall. Split it into words, show every word in a dim but readable grey, and light the words up one by one in step with the scroll, so how far the reader has scrolled decides how much is lit and scrolling back up un-lights them. When the settings include it, show the next word to fill in a highlight color, like a reading cursor. Keep it real text for screen readers. If the visitor has reduced motion turned on, change each word's color without fading. 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>
- <label class="tog" for="cursor-tog"><input type="checkbox" id="cursor-tog" checked><span>Highlight active word</span></label>
- </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>Key statements</li><li>Manifestos</li><li>Landing page intros</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Body text</li><li>Long articles</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'),textEl=$('fill-text');
- const progKv=$('prog-kv'),wordsKv=$('words-kv');
- const completeSl=$('complete-sl'),completeVal=$('complete-val');
- const cursorTog=$('cursor-tog');
+ const stage=document.getElementById('stage'),textEl=document.getElementById('fill-text');
+ const cursorTog=document.getElementById('cursor-tog'),colorSetting=document.getElementById('color-setting');
const clamp=(v,a,b)=>Math.min(Math.max(v,a),b);
- const COPY="Scroll is not a play button. It is a position — and a position can drive anything. "+
- "Here every word watches the same number: how far you have travelled through this passage. "+
- "Words behind that point light up. Words ahead of it wait in the dark. "+
- "Pause anywhere and the sentence holds its state, because nothing is animating — you are simply somewhere. "+
- "Scroll back up and watch the paragraph un-read itself, one word at a time, in perfect reverse.";
+ const COPY="Scroll is not a play button. It is a position. Every word here watches how far you have read. "+
+ "Words behind that point light up; words ahead wait in the dark. Stop anywhere and the sentence holds still. "+
+ "Scroll back up and it un-reads itself, word by word.";
// one span per word, built once
const words=COPY.split(' ').map(w=>{
@@ -149,23 +159,27 @@ body{padding-top:46px}
const N=words.length;
let completeAt=.9,maxScroll=1,ticking=false;
- let lastFilled=-1,lastCursor=-1,lastPct=-1;
+ let lastFilled=-1,lastCursor=-1;
- // Layout reads live here only — never in the scroll handler.
- function measure(){maxScroll=Math.max(1,stage.scrollHeight-stage.clientHeight)}
+ // Layout reads live here only, never in the scroll handler. 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 last word must still light.
+ function measure(){maxScroll=Math.max(1,stage.scrollHeight-stage.clientHeight-1)}
function render(){
+ ticking=false;
const p=clamp(stage.scrollTop/maxScroll,0,1);
const e=clamp(p/completeAt,0,1);
const filled=Math.floor(e*N+1e-6);
- // Only touch words whose state actually changed — never rewrite all spans.
+ // Only touch words whose state actually changed, never rewrite all spans.
if(filled!==lastFilled){
const prev=lastFilled<0?0:lastFilled;
const lo=Math.min(filled,prev),hi=Math.max(filled,prev);
+ const jump=hi-lo>N/4;
+ if(jump)textEl.classList.add('jump');
for(let i=lo;i<hi;i++)words[i].classList.toggle('on',i<filled);
+ if(jump){void textEl.offsetWidth;textEl.classList.remove('jump')}
lastFilled=filled;
- wordsKv.textContent=`${filled} / ${N}`;
}
const cursor=(cursorTog.checked&&filled<N&&e>0)?filled:-1;
if(cursor!==lastCursor){
@@ -173,25 +187,25 @@ body{padding-top:46px}
if(cursor>=0)words[cursor].classList.add('cursor');
lastCursor=cursor;
}
- const pct=Math.round(p*100);
- if(pct!==lastPct){progKv.textContent=pct+'%';lastPct=pct}
- ticking=false;
}
stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(render);ticking=true}},{passive:true});
- completeSl.addEventListener('input',()=>{
- completeAt=completeSl.value/100;completeVal.textContent=completeSl.value+'%';render();
- });
- $('swatches').addEventListener('click',e=>{
- const b=e.target.closest('.swatch');if(!b)return;
- document.querySelectorAll('.swatch').forEach(s=>s.classList.toggle('on',s===b));
- textEl.style.setProperty('--fill-accent',b.dataset.c);
- });
- cursorTog.addEventListener('change',render);
- let rt;addEventListener('resize',()=>{clearTimeout(rt);rt=setTimeout(()=>{measure();render()},150)});
+ // the box changes height under the same scroll position, so measure again and draw at once
+ window.addEventListener('resize',()=>{measure();render()});
+ if(document.fonts&&document.fonts.ready)document.fonts.ready.then(()=>{measure();render()});
+
+ 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('finish-seg',d=>{completeAt=+d.at;render()});
+ choices('color-sw',d=>textEl.style.setProperty('--fill-accent',d.c));
+ cursorTog.addEventListener('change',()=>{colorSetting.hidden=!cursorTog.checked;render()});
measure();render();
</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 60ed037a..eceae8a8 100644
--- a/index.html
+++ b/index.html
@@ -900,7 +900,7 @@ const CATS=[
['zoom-into-image','Zoom Into Image','A small window opens up to fill the box as you scroll. Best for hero images.'],
['scroll-image-sequence','Scroll Image Sequence','Scrolling plays a series of pictures like a flip-book. Best for products.'],
['smooth-scroll','Smooth (Inertia) Scroll','Wheel and touch input eased toward a target each frame — weighted, gliding momentum instead of native jumps.'],
- ['text-fill-on-scroll','Text Fill on Scroll','A pinned paragraph fills word by word as you scroll — pause mid-read, scroll back and it un-reads.'],
+ ['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','Content shears with scroll speed and springs straight when you stop — motion mapped to velocity, not position.'],
['svg-line-draw','SVG Line Draw on Scroll','A winding route draws itself down the page via stroke-dashoffset, passing waypoints as you travel.'],
['scrollspy-nav','Scrollspy Navigation','A nav rail tracks the section in view with a sliding indicator — the docs-site pattern.'],