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 Cover Card to Fixed Header to the guided-steps page
matinf1116689c0ac
diff --git a/animations/01-scroll-based/cover-card-to-fixed-header/README.md b/animations/01-scroll-based/cover-card-to-fixed-header/README.mdindex 8e38c298..7ad3eb2a 100644--- a/animations/01-scroll-based/cover-card-to-fixed-header/README.md+++ b/animations/01-scroll-based/cover-card-to-fixed-header/README.md@@ -4,13 +4,11 @@## What it is-A large hero cover card that smoothly morphs into a compact fixed header as-the user scrolls. Height, font size, background opacity, blur, and element-visibility are all tied to a single progress value `p ∈ [0, 1]` derived from-scroll position. At `p = 0` the full cover is visible; at `p = 1` a minimal-header is pinned to the top. Every value between those extremes is a-deliberate, intentional intermediate state — not an accidental artifact of-a CSS transition.+A cover card to fixed header starts a page with a tall cover that holds the+title, a subtitle, the date and the author, and shrinks it into a slim header as+you scroll. Every change, from the cover's height and the title's size to the+fading background and the small author badge, follows one number that runs from+0 to 1 with the scroll, so every moment in between looks planned.## When to use it@@ -34,11 +32,11 @@ Eight properties are then interpolated against `e` in a single`requestAnimationFrame` callback:```js-cover.style.height = lerp(530, 56, e) + 'px';+cover.style.height = lerp(FULL, 56, e) + 'px'; // FULL: 85% of the box's heightcoverTitle.style.transform = `scale(${lerp(1, 13 / 26, e)})`;coverBg.style.opacity = lerp(1, 0.12, e);coverBg.style.filter = `blur(${lerp(0, 6, e)}px)`;-coverMeta.style.opacity = 1 - clamp(e * 3, 0, 1); // also coverSub, coverCode+coverMeta.style.opacity = 1 - clamp(e * 3, 0, 1); // also coverSubcoverAuthor.style.opacity = 1 - clamp(e * 2, 0, 1);headerChip.style.opacity = clamp((e - 0.5) * 2, 0, 1);coverRule.style.opacity = e;@@ -54,12 +52,8 @@ position on its own.| Parameter | Default | Effect ||-----------|---------|--------|-| `RANGE` | 320px | Scroll distance over which the morph completes |-| Cover full height | 530px (desktop) / 480px (mobile) | Starting cover height |-| Cover min height | 56px (desktop) / 64px (mobile) | Collapsed header height |-| Easing | easeOutCubic | Brisk start, settled finish |-| `EASE` | 0.16 | Share of the remaining collapse covered per frame. Lower = smoother but laggier; above ~0.3 a wheel notch reads as a jump again |-| `BLUR_STEP` | 0.5px | Granularity the backdrop blur snaps to, so the compositor can reuse its cached texture |+| Shrink distance | Medium | How far you scroll before the cover is fully small: short is 200px, medium 320px and long 440px |+| Snaps at halfway | off | Switches between the tall cover and the slim header at half the distance instead of shrinking with the scroll; reduced motion always does this |## Production notes@@ -107,7 +101,6 @@ position on its own.## See also-- [Parallax Scrolling](../parallax-scrolling/) — single progress value driving- speed-ratio depth; the same interpolation model applied to layer motion.-- [Reverse-Scrolling Columns](../reverse-scrolling-columns/) — another- scroll-progress pattern, this time driving directional column motion.+- [Pin Animation](../pin-animation/) — one part holds still while the page scrolls past+- [Stacking Cards](../stacking-cards/) — cards pile into a deck as you scroll+- [Scrub Animation](../scrub-animation/) — scroll plays an animation forward and backdiff --git a/animations/01-scroll-based/cover-card-to-fixed-header/index.html b/animations/01-scroll-based/cover-card-to-fixed-header/index.htmlindex 2b36fef2..1c0881a7 100644--- a/animations/01-scroll-based/cover-card-to-fixed-header/index.html+++ b/animations/01-scroll-based/cover-card-to-fixed-header/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Cover Card to Fixed Header — Animation Handbook</title>- <meta name="description" content="A full-page hero cover morphs into a compact fixed header as you scroll — every property scrubbed to a single 0→1 progress value.">+ <meta name="description" content="A tall cover shrinks into a slim header as you scroll. Best for articles."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/cover-card-to-fixed-header/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,249 +12,199 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Cover Card to Fixed Header — Animation Handbook">- <meta property="og:description" content="A full-page hero cover morphs into a compact fixed header as you scroll — every property scrubbed to a single 0→1 progress value.">+ <meta property="og:description" content="A tall cover shrinks into a slim header as you scroll. Best for articles."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/cover-card-to-fixed-header/"><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="Cover Card to Fixed Header — Animation Handbook">- <meta name="twitter:description" content="A full-page hero cover morphs into a compact fixed header as you scroll — every property scrubbed to a single 0→1 progress value.">+ <meta name="twitter:description" content="A tall cover shrinks into a slim header as you scroll. Best for articles."><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": "Cover Card to Fixed Header", "name": "Cover Card to Fixed Header", "description": "A full-page hero cover morphs into a compact fixed header as you scroll — every property scrubbed to a single 0→1 progress value.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/cover-card-to-fixed-header/", "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, Cover Card to Fixed Header"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Cover Card to Fixed Header", "name": "Cover Card to Fixed Header", "description": "A tall cover shrinks into a slim header as you scroll. Best for articles.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/cover-card-to-fixed-header/", "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, Cover Card to Fixed Header"}</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;- --cover-full:530px;--cover-min:56px;- --disp:'Bricolage','Arial Narrow',sans-serif;- --mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;- }+ :root{--ui-accent:#6ea8ff;--ui-text:#f4f4f2;--ui-muted:#8a8a92;--cover-min:56px}*,*::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:620px;- overflow-y:scroll;scrollbar-width:none;- border:1px solid var(--ui-border);border-radius:8px;+ position:relative;overflow-y:auto;scrollbar-width:none;container-type:size;background:#0b0b0d;/* The cover shrinking above the viewport makes scroll anchoring claw scrollTopback, which lowers progress, which re-grows the cover — a feedback loop thatstalls the collapse partway. Any scroll-driven size change needs this off. */overflow-anchor:none;}.stage::-webkit-scrollbar{display:none}- .scene{min-height:2500px;position:relative}+ .scene{position:relative}- .cover{position:sticky;top:0;z-index:10;height:var(--cover-full);overflow:hidden;background:#050e08}- .cover-bg{- position:absolute;inset:0;- background:linear-gradient(150deg,#050e08,#0c2820,#060a10);- will-change:opacity,filter;- }- .cover-code{- position:absolute;top:14px;left:16px;- font-size:9px;color:#1a4a30;line-height:1.7;- pointer-events:none;user-select:none;- }+ .cover{position:sticky;top:0;z-index:10;height:85cqh;overflow:hidden;background:#050e08}+ .cover-bg{position:absolute;inset:0;background:linear-gradient(150deg,#050e08,#0c2820,#060a10);will-change:opacity,filter}.cover-inner{position:relative;z-index:1;display:flex;flex-direction:column;height:100%;padding:0 24px 20px}.cover-spacer{flex:1}- .cover-meta{font-size:10px;color:#3d7a52;letter-spacing:1px;text-transform:uppercase;margin-bottom:8px}+ .cover-meta{font-size:11px;color:#5fa577;letter-spacing:1px;text-transform:uppercase;margin-bottom:8px}/* scaled rather than re-sized: font-size re-shapes the text every frame */- .cover-title{font-size:26px;color:#d1f7d6;line-height:1.2;letter-spacing:-.5px;margin-bottom:8px;+ .cover-title{font-size:26px;font-weight:700;color:#d1f7d6;line-height:1.2;letter-spacing:-.5px;margin-bottom:8px;transform-origin:left top;will-change:transform}/* the collapsed header's hairline, faded in — cheaper than writing box-shadow per frame */.cover-rule{position:absolute;left:0;right:0;bottom:0;height:1px;background:#3fb950;opacity:0;pointer-events:none}- .cover-sub{- font-size:12px;color:#3d7a52;line-height:1.5;margin-bottom:14px;- }+ .cover-sub{font-size:14px;color:#5fa577;line-height:1.5;margin-bottom:14px}.cover-author{display:flex;align-items:center;gap:8px}- .avatar{- width:24px;height:24px;border-radius:50%;flex-shrink:0;- background:linear-gradient(135deg,#3fb950,#56d364);- }- .author-name{font-size:10px;color:#3d7a52}- .header-chip{- position:absolute;top:14px;right:16px;- display:flex;align-items:center;gap:6px;opacity:0;- }- .avatar-sm{- width:16px;height:16px;border-radius:50%;flex-shrink:0;- background:linear-gradient(135deg,#3fb950,#56d364);- }- .chip-name{font-size:10px;color:#d1f7d6}+ .avatar{width:24px;height:24px;border-radius:50%;flex-shrink:0;background:linear-gradient(135deg,#3fb950,#56d364)}+ .author-name{font-size:11px;color:#5fa577}+ .header-chip{position:absolute;top:14px;right:16px;display:flex;align-items:center;gap:6px;opacity:0}+ .avatar-sm{width:16px;height:16px;border-radius:50%;flex-shrink:0;background:linear-gradient(135deg,#3fb950,#56d364)}+ .chip-name{font-size:11px;color:#d1f7d6}.article-body{padding:28px 24px;max-width:600px}- .article-body h2{- font-size:11px;color:var(--ui-accent);letter-spacing:1px;- text-transform:uppercase;margin:28px 0 10px;- }- .article-body p{- font-size:12px;color:var(--ui-muted);line-height:1.75;margin-bottom:14px;- }- .article-body blockquote{- border-left:2px solid var(--ui-accent);padding:8px 16px;margin:18px 0;- font-size:13px;color:var(--ui-text);font-style:italic;- }-- 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)}- .row{display:flex;justify-content:space-between;font-size:10px}- .row .v{color:var(--ui-text)}- .tbl{display:flex;flex-direction:column;gap:2px}- .tbl .row{font-size:10px;color:var(--ui-muted)}- .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)}- .div{height:1px;background:var(--ui-border)}- .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}- button{- background:transparent;border:1px solid var(--ui-border);- color:var(--ui-text);font-family:monospace;font-size:10px;- padding:17px 8px;border-radius:4px;cursor:pointer;width:100%;- }- button:hover{border-color:var(--ui-accent);color:var(--ui-accent)}-- @media(max-width:600px){- .layout{flex-direction:column}- aside{width:100%}.stage{flex:none;width:100%}- .stage{height:520px}- :root{--cover-full:480px;--cover-min:64px}- }- @media(prefers-reduced-motion:reduce){- .cover,.cover-title,.cover-bg,.header-chip{will-change:auto}- }+ .article-body h3{font-size:12px;color:var(--ui-accent);letter-spacing:1px;text-transform:uppercase;margin:28px 0 10px}+ .article-body p{font-size:14px;color:var(--ui-muted);line-height:1.75;margin-bottom:14px}+ .article-body blockquote{border-left:2px solid var(--ui-accent);padding:8px 16px;margin:18px 0;font-size:15px;color:var(--ui-text)}+ /* fills the space the slim cover leaves after the article */+ .end-cue{position:absolute;left:0;right:0;bottom:0;margin:0;display:flex;align-items:center;justify-content:center;+ font-size:13px;color:#8a8a92;letter-spacing:.1em;text-align:center;padding:0 24px}++ @media(max-width:600px){:root{--cover-min:64px}}+ @media(prefers-reduced-motion:reduce){.cover,.cover-title,.cover-bg,.header-chip{will-change:auto}}</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="../reverse-scrolling-columns/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../fly-in-fly-out-contact-list/" 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/cover-card-to-fixed-header/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></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="../reverse-scrolling-columns/" rel="prev" aria-label="Previous: Reverse-Scrolling Columns"><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>Reverse-Scrolling Columns</span></a><a href="../fly-in-fly-out-contact-list/" rel="next" aria-label="Next: Fly-in Fly-out Contact List"><span><span class="hb-dir">Next: </span>Fly-in Fly-out Contact List</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.04 · Scroll-Based</p>+ <h1>Cover Card to Fixed Header</h1>+ <p class="hb-lede">A tall cover shrinks into a slim header as you scroll. Best for articles.</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="An article with a tall cover">+ <div class="scene" id="scene">++ <div class="cover" id="cover">+ <div class="cover-bg" id="cover-bg"></div>+ <div class="cover-inner">+ <div class="cover-spacer"></div>+ <div class="cover-meta" id="cover-meta">Article · 8 min read</div>+ <p class="cover-title" id="cover-title">The Architecture<br>of Scroll Motion</p>+ <p class="cover-sub" id="cover-sub">Why a tall cover can fold into a slim bar as you read</p>+ <div class="cover-author" id="cover-author">+ <div class="avatar"></div>+ <span class="author-name">Matin M. · May 2026</span>+ </div>+ </div>+ <div class="cover-rule" id="cover-rule" aria-hidden="true"></div>+ <div class="header-chip" id="header-chip">+ <div class="avatar-sm"></div>+ <span class="chip-name">Matin M.</span>+ </div>+ </div>-<header>- <h1>Cover Card to Fixed Header</h1>- <p>A full-page hero cover morphs into a compact fixed header as you scroll — every property scrubbed to a single 0→1 progress value.</p>-</header>+ <article class="article-body">+ <h3>One number drives it all</h3>+ <p>As you scroll, one number moves from 0 to 1. The cover's height, the size of the title, the fading background and the small author badge all follow that number, so every moment in between looks planned.</p>+ <blockquote>A header should get out of the way without disappearing.</blockquote>+ <h3>Everything moves together</h3>+ <p>The title shrinks toward the top-left corner while the subtitle and the date fade out first, so the slim bar never looks crowded.</p>+ <p>The author's name fades into the corner of the bar in the second half of the fold, when there is room for it.</p>+ <h3>Room to read</h3>+ <p>Once the cover has folded away, only a slim bar stays at the top, with the title and the author, and the rest of the box goes to the text.</p>+ <p>Scroll back up and the cover opens again, step by step, in exactly the reverse order.</p>+ </article>-<div class="layout">+ <p class="end-cue">The end · scroll back up and the cover opens again</p>- <div class="stage" id="stage">- <div class="scene" id="scene">+ </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>- <div class="cover" id="cover">- <div class="cover-bg" id="cover-bg"></div>- <div class="cover-code" id="cover-code" aria-hidden="true">- const p = stage.scrollTop / RANGE;<br>- const e = easeOutCubic(p);<br>- height = lerp(530, 56, e);- </div>- <div class="cover-inner">- <div class="cover-spacer"></div>- <div class="cover-meta" id="cover-meta">Article · 8 min read</div>- <h1 class="cover-title" id="cover-title">The Architecture<br>of Scroll Motion</h1>- <p class="cover-sub" id="cover-sub">How browsers render scroll-driven animations at 60fps</p>- <div class="cover-author" id="cover-author">- <div class="avatar"></div>- <span class="author-name">Matin M. · May 2026</span>- </div>- </div>- <div class="cover-rule" id="cover-rule" aria-hidden="true"></div>- <div class="header-chip" id="header-chip">- <div class="avatar-sm"></div>- <span class="chip-name">Matin M.</span>+ <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="range-lbl">Shrink distance</p>+ <div class="seg" id="range-seg" role="group" aria-labelledby="range-lbl">+ <button type="button" data-range="200" aria-pressed="false">Short</button>+ <button type="button" data-range="320" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-range="440" aria-pressed="false">Long</button></div>+ <p class="hb-hint">How far you scroll before the cover is fully small.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Snaps at halfway</span><input class="hb-switch" type="checkbox" role="switch" id="snap-tog" autocomplete="off"></label>+ <p class="hb-hint">Jumps from tall to slim instead of shrinking smoothly.</p></div>-- <article class="article-body">- <h2>Render Pipeline</h2>- <p>Compositor-only properties (transform, opacity) bypass layout and paint entirely. Animating height forces layout on every frame — the production alternative is clip-path or scaleY on a fixed-height container.</p>- <blockquote>"The fastest animation is one the compositor runs without consulting the main thread."</blockquote>- <h2>Single-Progress Model</h2>- <p>One value p ∈ [0, 1] drives all eight properties simultaneously. When everything shares the same source of truth, every intermediate scroll position has a consistent, intentional appearance.</p>- <p>Easing p once (easeOutCubic) rather than each property separately keeps multi-property deceleration coherent. Use the transition range slider to feel how the same logic produces very different pacing.</p>- </article>-</div>- </div>-- <aside>- <p class="note">This pattern is the foundation of every good article header on the modern web — Medium, Substack, NYT, Stripe blog. The trick is scrubbing every property to a single 0→1 progress value so intermediate states all look intentional.</p>+ </section>- <div>- <div class="lbl">Progress</div>- <div class="tbl">- <div class="row"><span>Scroll</span><span class="v" id="scroll-prog">0%</span></div>- <div class="row"><span>Collapse</span><span class="v" id="collapse-prog">0%</span></div>+ <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">3</span>+ <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>+ </div>+ <div class="hb-card">+ <p class="hb-prompt">Add a collapsing cover to [your article or page header]. Start with a tall cover pinned to the top that holds the title, a subtitle, the date and the author. As the visitor scrolls, shrink it into a slim header: the title scales down into the corner, the subtitle and date fade out first, and a small author badge fades in near the end. Unless the settings make it snap, tie every change to one number that runs from 0 to 1 with the scroll, so every moment in between looks planned and scrolling back reverses it. Turn off scroll anchoring on the scrolling area. If the visitor has reduced motion turned on, switch between the tall and slim cover halfway, without animating. 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>- <div class="div"></div>- <div>- <div class="lbl" id="col-lbl">Collapse Override</div>- <div class="sr"><input type="range" id="collapse-slider" aria-labelledby="col-lbl" min="0" max="100" value="0"><span class="sv" id="col-val">0%</span></div>+ <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>- <div class="lbl" id="range-lbl">Transition Range</div>- <div class="sr"><input type="range" id="range-slider" aria-labelledby="range-lbl" min="150" max="600" step="10" value="320"><span class="sv" id="range-val">320px</span></div>+ <div class="hb-fit">+ <h2>Good for</h2>+ <ul class="hb-tags hb-good"><li>Articles</li><li>Blog posts</li><li>Product pages</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Short pages</li><li>App screens</li></ul></div>- <div class="div"></div>- <label class="tog" for="binary-tog"><input type="checkbox" id="binary-tog"><span>Binary (snap at midpoint)</span></label>- <button id="reset-btn">Reset scroll</button>- </aside>--</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 cover = $('cover'), coverBg = $('cover-bg'), coverMeta = $('cover-meta');const coverTitle = $('cover-title'), coverSub = $('cover-sub'), coverAuthor = $('cover-author');- const coverCode = $('cover-code');const headerChip = $('header-chip'), coverRule = $('cover-rule'), stage = $('stage');- const scrollProg = $('scroll-prog'), collapseProg = $('collapse-prog');- const colSlider = $('collapse-slider'), colVal = $('col-val');- const rangeSlider = $('range-slider'), rangeVal = $('range-val');- const binaryTog = $('binary-tog'), resetBtn = $('reset-btn');+ const scene = $('scene'), snapTog = $('snap-tog');+ const article = document.querySelector('.article-body'), endCue = document.querySelector('.end-cue');const motionMQ = window.matchMedia('(prefers-reduced-motion: reduce)');- // Heights come from CSS variables, which the mobile media query overrides — so they- // are re-read in measure(), not frozen at startup, or a rotation across the 600px- // breakpoint would leave the collapsed header at the desktop size.- let FULL = 530, MIN = 56;+ // The full cover is 85% of the box and the slim one comes from a CSS variable that the phone rule+ // overrides — so both are re-read in measure(), not frozen at startup, or a rotation across the+ // 600px breakpoint would leave the collapsed header at the desktop size.+ let FULL = 0, MIN = 56;// A wheel notch is ~100px — nearly a third of RANGE — and easeOutCubic turns that// first notch into 68% of the collapse. Scroll therefore sets a *target* and the// rendered progress eases toward it, so the header glides instead of snapping.const EASE = 0.16, BLUR_STEP = 0.5;- let RANGE = 320, manual = false, raf = null, target = 0, current = 0, maxScroll = 1;+ let RANGE = 320, raf = null, target = 0, current = 0;function lerp(a, b, t) { return a + (b - a) * t; }function clamp(v, lo, hi) { return Math.min(Math.max(v, lo), hi); }@@ -266,22 +216,21 @@ body{padding-top:46px}const set = (k, v, fn) => { if (G[k] !== v) { G[k] = v; fn(v); } };const q = (v, step) => Math.round(v / step) * step;- // scrollHeight/clientHeight are layout reads: cache them instead of paying a- // forced reflow on every scroll event.+ // Layout reads live here, not in the scroll handler. The scene is as tall as the full cover plus the+ // article, and at least a box plus the longest shrink: the box always scrolls far enough to finish+ // the shrink, and its scroll length does not change while the cover shrinks. What the slim cover+ // frees after the article is filled by the closing line. The article's height depends on the font.function measure() {- const cs = getComputedStyle(document.documentElement);- FULL = parseFloat(cs.getPropertyValue('--cover-full')) || 530;- MIN = parseFloat(cs.getPropertyValue('--cover-min')) || 56;- maxScroll = Math.max(1, stage.scrollHeight - stage.clientHeight);+ MIN = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--cover-min')) || 56;+ FULL = Math.round(stage.clientHeight * 0.85);+ scene.style.minHeight = Math.max(FULL + article.offsetHeight, stage.clientHeight + 440) + 'px';+ endCue.style.height = (FULL - MIN) + 'px';+ delete G.h; // the cover's height is written again with the new FULL}- // Scroll progress -> collapse amount. Binary mode and reduced motion snap by design.- const snaps = () => motionMQ.matches || binaryTog.checked;+ // Scroll progress -> collapse amount. Snapping at halfway and reduced motion snap by design.+ const snaps = () => motionMQ.matches || snapTog.checked;const curveOf = p => snaps() ? (p > 0.5 ? 1 : 0) : ease(p);- // The slider is also a readout — render() writes the collapse percentage back into- // it — so its value is already a collapse amount. Easing it a second time would make- // the number beside the slider disagree with the Collapse row.- const overrideOf = c => snaps() ? (c > 0.5 ? 1 : 0) : c;// Takes the finished collapse value, so easing it bounds how far the header can// travel in one frame — easing raw progress instead lets easeOutCubic (slope 3@@ -291,14 +240,10 @@ body{padding-top:46px}set('bgOp', q(lerp(1, .12, e), .01), v => coverBg.style.opacity = v);set('blur', q(lerp(0, 6, e), BLUR_STEP), v => coverBg.style.filter = v > 0 ? `blur(${v}px)` : 'none');set('scale', q(lerp(1, 13 / 26, e), .002), v => coverTitle.style.transform = `scale(${v})`);- set('fade', q(1 - clamp(e * 3, 0, 1), .01), v => { coverMeta.style.opacity = v; coverSub.style.opacity = v; coverCode.style.opacity = v; });+ set('fade', q(1 - clamp(e * 3, 0, 1), .01), v => { coverMeta.style.opacity = v; coverSub.style.opacity = v; });set('auth', q(1 - clamp(e * 2, 0, 1), .01), v => coverAuthor.style.opacity = v);set('chip', q(clamp((e - .5) * 2, 0, 1), .01), v => headerChip.style.opacity = v);set('rule', q(e, .01), v => coverRule.style.opacity = v);- set('pct', Math.round(e * 100), v => {- collapseProg.textContent = v + '%';- if (!manual) { colSlider.value = v; colVal.textContent = v + '%'; }- });}function tick() {@@ -314,48 +259,41 @@ body{padding-top:46px}}stage.addEventListener('scroll', () => {- manual = false;target = curveOf(clamp(stage.scrollTop / RANGE, 0, 1));- set('sp', Math.round(stage.scrollTop / maxScroll * 100), v => scrollProg.textContent = v + '%');schedule();}, { passive: true });- colSlider.addEventListener('input', () => {- manual = true;- colVal.textContent = colSlider.value + '%';- target = overrideOf(colSlider.value / 100);+ 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('range-seg', d => {+ RANGE = +d.range;+ target = curveOf(clamp(stage.scrollTop / RANGE, 0, 1));schedule();});- rangeSlider.addEventListener('input', () => {- RANGE = parseInt(rangeSlider.value);- rangeVal.textContent = RANGE + 'px';- if (!manual) { target = curveOf(clamp(stage.scrollTop / RANGE, 0, 1)); schedule(); }- });-- binaryTog.addEventListener('change', () => {+ snapTog.addEventListener('change', () => {for (const k in G) delete G[k]; // the curve changed, so every value is stale- target = manual ? overrideOf(colSlider.value / 100)- : curveOf(clamp(stage.scrollTop / RANGE, 0, 1));+ target = curveOf(clamp(stage.scrollTop / RANGE, 0, 1));schedule();});- resetBtn.addEventListener('click', () => {- manual = false; stage.scrollTop = 0;- target = current = 0;- render(0);- });-let rt;addEventListener('resize', () => {clearTimeout(rt);- rt = setTimeout(() => { measure(); delete G.h; render(current); }, 150);+ rt = setTimeout(() => { measure(); render(current); }, 150);});measure();target = current = curveOf(clamp(stage.scrollTop / RANGE, 0, 1));render(current);+ if (document.fonts && document.fonts.ready) {+ document.fonts.ready.then(() => { measure(); render(current); });+ }</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 a6b7e078..2e08e689 100644--- a/index.html+++ b/index.html@@ -882,7 +882,7 @@ const CATS=[['parallax-depth-of-field','Parallax Depth-of-Field','Layers move at their own speed as the focus shifts. Best for cinematic intros.'],['parallax-scrolling','Parallax Scrolling','Far layers move slower than near ones as you scroll. Best for hero scenes.'],['reverse-scrolling-columns','Reverse-Scrolling Columns','Side columns run the opposite way to the middle one. Best for portfolios.'],- ['cover-card-to-fixed-header','Cover Card to Fixed Header','A full-page hero morphs into a compact fixed header — every visual property scrubbed to a single progress value.'],+ ['cover-card-to-fixed-header','Cover Card to Fixed Header','A tall cover shrinks into a slim header as you scroll. Best for articles.'],['fly-in-fly-out-contact-list','Fly-in Fly-out Contact List','Rows translate and fade through entry, active, and exit zones as you scroll — bidirectional and continuous.'],['stacking-cards','Stacking Cards','CSS Scroll-Driven Animations fan cards into a deck — per-index sticky offset creates the visible peek tab.'],['scroll-trigger','ScrollTrigger Animation','The onEnter / onLeave lifecycle demonstrated with vanilla JS — four scroll trigger zones.'],