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: Hide-on-Scroll Header (01.27)
matin4f8a644cf6e8
diff --git a/README.md b/README.mdindex 60328023..28903928 100644--- a/README.md+++ b/README.md@@ -68,6 +68,7 @@ All 129 techniques, each linked to its live demo.- **[SVG Line Draw on Scroll](animations/01-scroll-based/svg-line-draw/)** — A line draws itself along a route as you scroll. Best for timelines.- **[Scrollspy Navigation](animations/01-scroll-based/scrollspy-nav/)** — A menu highlights the section you are reading. Best for long docs.- **[Scroll-Driven Background Color](animations/01-scroll-based/scroll-background-color/)** — The background color changes as you scroll through sections. Best for stories.+- **[Hide-on-Scroll Header](animations/01-scroll-based/hide-on-scroll-header/)** — The top bar slides away as you scroll down and comes back as you scroll up. Best for mobile pages.</details>diff --git a/animations/01-scroll-based/README.md b/animations/01-scroll-based/README.mdindex 317e6337..57c5f88e 100644--- a/animations/01-scroll-based/README.md+++ b/animations/01-scroll-based/README.md@@ -30,3 +30,4 @@ Techniques driven by scroll position.- [SVG Line Draw on Scroll](svg-line-draw/) — A line draws itself along a route as you scroll. Best for timelines.- [Scrollspy Navigation](scrollspy-nav/) — A menu highlights the section you are reading. Best for long docs.- [Scroll-Driven Background Color](scroll-background-color/) — The background color changes as you scroll through sections. Best for stories.+- [Hide-on-Scroll Header](hide-on-scroll-header/) — The top bar slides away as you scroll down and comes back as you scroll up. Best for mobile pages.diff --git a/animations/01-scroll-based/hide-on-scroll-header/README.md b/animations/01-scroll-based/hide-on-scroll-header/README.mdnew file mode 100644index 00000000..2b890224--- /dev/null+++ b/animations/01-scroll-based/hide-on-scroll-header/README.md@@ -0,0 +1,74 @@+# Hide-on-Scroll Header++## What it is++A hide-on-scroll header is a top bar that gets out of the way while you read. Scrolling down slides it up out of view, so the content gets the whole screen; scrolling back up brings it back, so the menu is always one small move away. Near the top of the page it always shows.++## When to use it++- Mobile sites, where a bar that stays in place takes a large share of a small screen+- News sites, blogs and long articles, where readers mostly scroll down and only now and then want the menu+- Shops and catalogs whose bar holds search and the cart, which visitors want back quickly without scrolling all the way up+- Any sticky header that covers too much of the content while people read++## How it works++The bar is placed over the page (in the demo it sits over the scrolling box; on a real page it is fixed or sticky), and the content gets top padding of the bar's height so nothing starts underneath it. The scroll listener does no work of its own: it asks for one update on the next animation frame. The update compares the scroll position with the last one it acted on. A move down hides the bar, a move up shows it, and anywhere near the top it always shows. A move of a few pixels is ignored, and the last position is only updated when a move counts, so a slow scroll still adds up.++```js+function update() {+ ticking = false;+ const y = Math.min(Math.max(scroller.scrollTop, 0), maxY); // the rubber-band bounce at either end does not count+ if (y <= nearTop) { setAway(false); lastY = y; return; } // near the top: always shown+ const dy = y - lastY;+ if (Math.abs(dy) < JITTER) return; // a few pixels of jitter: ignored+ if (dy > 0) setAway(true); // down: away+ else if (comeBack === 'any') setAway(false); // up: back (with "Only near the top", only the top does it)+ lastY = y;+}+scroller.addEventListener('scroll', () => {+ if (!ticking) { ticking = true; requestAnimationFrame(update); }+}, { passive: true });+```++`setAway()` only toggles a class. The stylesheet moves the bar with a transform, so the page below never reflows; the shrinking version keeps a slim strip of the bar in view and scales its contents to fit it:++```css+.topbar { position: absolute; top: 0; left: 0; right: 0; transition: transform var(--dur) var(--ease); }+.topbar.away { transform: translateY(calc(-100% - 2px)); } /* its height and its border */+.shrink .topbar.away { transform: translateY(-18px); } /* a slim strip stays */+.shrink .topbar.away .brand { transform: translateY(9px) scale(.82); } /* centered in the strip */++@media (prefers-reduced-motion: reduce) {+ .topbar { transition: opacity var(--dur) linear; }+ .topbar.away { transform: none; opacity: 0; } /* it fades instead of sliding */+}+```++Show me scrolls the box itself, one and a half boxes down and back, with each frame's position worked out from the time since the glide began, so it takes as long on a 120 Hz screen as on a 60 Hz one.++## Key parameters++| Parameter | Default | Effect |+|-----------|---------|--------|+| Speed | Normal | How long the slide takes: slow is 700ms, normal 300ms and fast 150ms |+| Comes back | On any scroll up | On any scroll up brings the bar back at the first move up; Only near the top keeps it away until the page is back within two bar heights of the top |+| Shrinks instead of hiding | Off | Keeps a slim strip of the bar in view, with smaller contents, instead of sliding it all away |++## Production notes++- **Sticky or fixed**: on a real page use `position: fixed` (with top padding on the page) or `position: sticky`, and set `scroll-padding-top` to the bar's height so links to headings and focused form fields are not hidden under the bar when it is showing.+- **Keep the threshold**: trackpads and touch screens report many tiny moves and small reversals. Without a few pixels of tolerance the bar flickers in and out.+- **Clamp the position**: iOS rubber-band scrolling reports negative positions at the top and positions past the end at the bottom. The bounce back from the end would otherwise read as a scroll up and pop the bar back in.+- **Keyboard users**: show the bar when focus moves into it (`:focus-within`), or a visitor tabbing to the menu ends up on links they cannot see.+- **Transform only**: never animate `top`, `margin` or `height`. Moving the bar with a transform keeps it on the compositor, and the shrinking version scales the contents instead of changing font sizes.+- **Reduced motion**: fade the bar out and in, or leave it in place, instead of sliding it.+- **Do not hide key actions**: a bar that holds the main button of the page (checkout, compose, save) should stay.+- **Libraries**: Headroom.js does exactly this, with options for the threshold and the offset from the top; in React or Vue a small scroll-direction hook does the same. CSS scroll-driven animations cannot read the scroll direction yet, so the direction check stays in JavaScript.++## See also++- [Cover Card to Fixed Header](../cover-card-to-fixed-header/) — a tall cover shrinks into a slim header as you scroll+- [Scrollspy Navigation](../scrollspy-nav/) — a menu highlights the section you are reading+- [Progress Bar](../progress-bar/) — a bar fills as you read down the page+- [Smooth (Inertia) Scroll](../smooth-scroll/) — scrolling glides to a stop instead of jumpingdiff --git a/animations/01-scroll-based/hide-on-scroll-header/index.html b/animations/01-scroll-based/hide-on-scroll-header/index.htmlnew file mode 100644index 00000000..1426daea--- /dev/null+++ b/animations/01-scroll-based/hide-on-scroll-header/index.html@@ -0,0 +1,281 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Hide-on-Scroll Header — Animation Handbook</title>+ <meta name="description" content="The top bar slides away as you scroll down and comes back as you scroll up. Best for mobile pages.">+ <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/hide-on-scroll-header/">+ <link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">+ <link rel="icon" type="image/svg+xml" href="../../../favicon.svg">+ <link rel="apple-touch-icon" href="../../../apple-touch-icon.png">+ <meta property="og:type" content="article">+ <meta property="og:site_name" content="Animation Handbook">+ <meta property="og:title" content="Hide-on-Scroll Header — Animation Handbook">+ <meta property="og:description" content="The top bar slides away as you scroll down and comes back as you scroll up. Best for mobile pages.">+ <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/hide-on-scroll-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="Hide-on-Scroll Header — Animation Handbook">+ <meta name="twitter:description" content="The top bar slides away as you scroll down and comes back as you scroll up. Best for mobile pages.">+ <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": "Hide-on-Scroll Header", "name": "Hide-on-Scroll Header", "description": "The top bar slides away as you scroll down and comes back as you scroll up. Best for mobile pages.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/hide-on-scroll-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, Hide-on-Scroll Header"}</script>+ <style>+ :root{--ui-accent:#6ea8ff;--bar-h:56px;--dur:300ms;--ease:cubic-bezier(.2,.7,.3,1)}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ .stage{position:relative;overflow:hidden;background:#0b0b0d}+ /* The bar floats over the page and only ever moves with a transform; the page under it is what scrolls */+ .topbar{position:absolute;top:0;left:0;right:0;z-index:2;height:var(--bar-h);display:flex;align-items:center;justify-content:space-between;gap:12px;+ padding:0 clamp(14px,3vw,24px);background:#171920;border-bottom:1px solid rgba(255,255,255,.1);+ transition:transform var(--dur) var(--ease),opacity var(--dur) var(--ease);will-change:transform}+ .brand,.nav,.menu{display:flex;align-items:center;transition:transform var(--dur) var(--ease)}+ .brand{gap:10px;transform-origin:left center;font-weight:700;font-size:17px;letter-spacing:-.01em;color:#f4f4f2;white-space:nowrap}+ .logo{width:22px;height:22px;border-radius:50%;background:var(--ui-accent);flex:none}+ .nav{gap:clamp(14px,2.4vw,24px);transform-origin:right center;font-size:14px;color:#adadb2}+ .menu{display:none;flex-direction:column;align-items:stretch;justify-content:center;gap:4px;width:20px;transform-origin:right center}+ .menu i{display:block;height:2px;border-radius:1px;background:#d6d6da}+ /* Scrolled down: the bar slides up by its own height, border included, out of view */+ .topbar.away{transform:translateY(calc(-100% - 2px))}+ /* Shrinks instead: a slim strip stays, its contents smaller and centered in what is left of it */+ .stage.shrink .topbar.away{transform:translateY(-18px)}+ .stage.shrink .topbar.away .brand{transform:translateY(9px) scale(.82)}+ .stage.shrink .topbar.away .nav,.stage.shrink .topbar.away .menu{transform:translateY(9px) scale(.9)}+ .snap,.snap *{transition:none!important}+ .scroller{position:absolute;inset:0;overflow-y:auto;scrollbar-width:none;padding-top:var(--bar-h)}+ .scroller::-webkit-scrollbar{display:none}+ .post{max-width:640px;margin:0 auto;padding:clamp(22px,4vw,40px) clamp(16px,4vw,32px) 40px}+ .kicker{font-size:13px;font-weight:600;letter-spacing:.08em;text-transform:uppercase;color:var(--ui-accent)}+ .post h3{margin:10px 0 12px;font-weight:800;font-size:clamp(24px,3.6vw,34px);line-height:1.15;letter-spacing:-.02em;color:#f4f4f2}+ .post h4{margin:30px 0 8px;font-weight:700;font-size:clamp(18px,2.4vw,21px);color:#f4f4f2}+ .post p{font-size:15px;line-height:1.7;color:#adadb2}+ .post .lead{font-size:17px;color:#d6d6da}+ .pic{margin-top:26px;aspect-ratio:16/7;border-radius:10px;background:linear-gradient(135deg,#1f3a66,#3d2a5c 55%,#5a2d45)}+ .pic.two{background:linear-gradient(135deg,#123d3a,#1f3a66 60%,#2b2f45)}+ .post .end{margin-top:30px;padding-top:18px;border-top:1px solid rgba(255,255,255,.09);color:#8a8a92}+ @media(max-width:600px){:root{--bar-h:52px}.nav{display:none}.menu{display:flex}}+ /* Reduced motion: the bar fades out and back instead of sliding, and the slim strip appears without moving */+ @media(prefers-reduced-motion:reduce){+ .topbar{transition:opacity var(--dur) linear;will-change:auto}+ .brand,.nav,.menu{transition:none}+ .topbar.away{transform:none;opacity:0}+ .stage.shrink .topbar.away{transform:translateY(-18px);opacity:1}+ }+ </style>+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=6">+ <script src="../../../assets/js/demo-page.js?v=6" defer></script>+</head>+<body class="hb" data-hb-kind="do" data-hb-autoplay>+<nav class="hb-bar" aria-label="Animation Handbook">+ <a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>+ <span class="hb-pager"><a href="../scroll-background-color/" rel="prev" aria-label="Previous: Scroll-Driven Background Color"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Scroll-Driven Background Color</span></a></span>+</nav>+<main class="hb-page">+ <header class="hb-head">+ <p class="hb-cat">01.27 · Scroll-Based</p>+ <h1>Hide-on-Scroll Header</h1>+ <p class="hb-lede">The top bar slides away as you scroll down and comes back as you scroll up. Best for mobile pages.</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 down inside the box, then back up, or press Show me.</p></div>+ </div>+ <div class="stage" id="stage">+ <div class="topbar" id="topbar" aria-hidden="true">+ <span class="brand"><span class="logo"></span>Field Notes</span>+ <span class="nav"><span>Latest</span><span>Topics</span><span>About</span></span>+ <span class="menu"><i></i><i></i><i></i></span>+ </div>+ <div class="scroller" id="scroller" tabindex="0" role="region" aria-label="A page whose top bar slides away as you scroll down">+ <article class="post">+ <p class="kicker">Field Notes · Design</p>+ <h3>A bar that steps aside while you read</h3>+ <p class="lead">Scroll down and the bar above slides out of the way. Scroll back up to bring it home.</p>+ <div class="pic" aria-hidden="true"></div>+ <h4>Scroll down</h4>+ <p>Reading down the page, you do not need the menu, so the bar slides up out of view and the story gets the whole screen.</p>+ <h4>Scroll back up</h4>+ <p>The bar returns: at the first move up, or only once you are back near the top, whichever the page asks for.</p>+ <div class="pic two" aria-hidden="true"></div>+ <h4>Near the top it stays</h4>+ <p>Close to the top of the page the bar always shows, whichever way you scroll.</p>+ <h4>Small moves do not count</h4>+ <p>A few pixels of jitter never flip the bar in and out, so it does not flicker.</p>+ <h4>It floats over the page</h4>+ <p>The bar sits on top of the page and moves with a transform, so nothing below it jumps.</p>+ <p class="end">The end of the page. Scroll back up.</p>+ </article>+ </div>+ </div>+ <div class="hb-player">+ <button class="hb-play" type="button" id="btn-demo" data-hb-demo><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z"/></svg>Show me</button>+ <button class="hb-play" type="button" id="btn-reset" data-hb-reset><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>Reset</button>+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo autocomplete="off"><span>Slow motion</span></label>+ </div>+ </section>++ <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 Show me.</p></div>+ </div>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="speed-lbl">Speed</p>+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">+ <button type="button" data-ms="700" aria-pressed="false">Slow</button>+ <button type="button" data-ms="300" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="150" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">How quickly the bar slides away and back.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="back-lbl">Comes back</p>+ <div class="seg" id="back-seg" role="group" aria-labelledby="back-lbl">+ <button type="button" data-back="any" class="on" aria-pressed="true">On any scroll up</button>+ <button type="button" data-back="top" aria-pressed="false">Only near the top</button>+ </div>+ <p class="hb-hint">Any scroll up keeps the menu one small move away.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Shrinks instead of hiding</span><input class="hb-switch" type="checkbox" role="switch" id="shrink-tog" autocomplete="off"></label>+ <p class="hb-hint">A slim bar stays in view instead of leaving.</p>+ </div>+ </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">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 hide-on-scroll header to [the top bar of your site]. When the visitor scrolls down, slide the bar up out of view, or shrink it to a slim strip if the settings ask for that; when they scroll back up, bring it back as the settings say. Tell the direction by comparing each scroll position with the last one, ignore moves of a few pixels so the bar never flickers, and always show it near the top of the page. Let the bar float over the content, move it only with a transform and read the scroll once per frame. Touch scrolling counts too. If the visitor has reduced motion turned on, fade the bar out and in instead. Match the settings listed below.</p>+ <div class="hb-chips-box" hidden>+ <p class="hb-chips-title">Your settings</p>+ <ul class="hb-chips"></ul>+ </div>+ <div class="hb-copy-row">+ <button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>+ <p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p>+ </div>+ </div>+ </section>++ <section class="hb-about" aria-labelledby="hb-what-title">+ <div class="hb-what">+ <h2 id="hb-what-title">What it is</h2>+ <div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>+ </div>+ <div class="hb-fit">+ <h2>Good for</h2>+ <ul class="hb-tags hb-good"><li>Mobile pages</li><li>News and blogs</li><li>Long articles</li><li>Online shops</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Short pages</li><li>Bars with key buttons</li></ul>+ </div>+ </section>++ <section class="hb-related" aria-labelledby="hb-related-title" hidden>+ <h2 id="hb-related-title">Similar animations</h2>+ <div class="hb-rel-list"></div>+ </section>+</main>+<footer class="hb-foot"><span>Animation Handbook</span><a href="#top">Back to top ↑</a></footer>+<script>+ const stage=document.getElementById('stage'),scroller=document.getElementById('scroller'),bar=document.getElementById('topbar');+ const slowTog=document.getElementById('slow-tog'),shrinkTog=document.getElementById('shrink-tog');+ const motionMQ=window.matchMedia('(prefers-reduced-motion: reduce)');+ const vars=document.documentElement.style;+ const JITTER=6,MOVE=1100,HOLD=500; // a move under JITTER px is ignored; a Show me glide takes MOVE ms each way+ let ms=300,comeBack='any',maxY=0,nearTop=112,lastY=0,away=false,ticking=false;+ let runFrame=0,runTimers=[],runFrom=0;++ // The visitor pressed, typed, scrolled or touched inside the stage: a Show me run under way stops where it is.+ document.addEventListener('hb:input',()=>{if(running())stopRun()});++ // Layout is read here, never in the scroll handler: at the start, after the site font loads and on resize.+ function measure(){maxY=Math.max(0,scroller.scrollHeight-scroller.clientHeight);nearTop=bar.offsetHeight*2}+ function setAway(on){if(on===away)return;away=on;bar.classList.toggle('away',on)}++ // Once per frame: near the top the bar always shows; below that, a move down hides it and a move up brings it back+ // (with "Only near the top", only the top does). lastY changes only on a move past JITTER, so a slow scroll still adds up.+ // The position is clamped, so the rubber-band bounce at either end of a touch scroll does not count as a move.+ function update(){+ ticking=false;+ const y=Math.min(Math.max(scroller.scrollTop,0),maxY);+ if(y<=nearTop){setAway(false);lastY=y;return}+ const dy=y-lastY;+ if(Math.abs(dy)<JITTER)return;+ if(dy>0)setAway(true);+ else if(comeBack==='any')setAway(false);+ lastY=y;+ }+ scroller.addEventListener('scroll',()=>{if(!ticking){ticking=true;requestAnimationFrame(update)}},{passive:true});++ // Slow motion makes the slide and Show me's glides three times longer (not the hold between them)+ function slow(){return slowTog.checked?3:1}+ function applySpeed(){vars.setProperty('--dur',ms*slow()+'ms')}+ slowTog.addEventListener('change',applySpeed);+ // The shared script switches Slow motion off without a change event when reduced motion turns on: read it again after it+ motionMQ.addEventListener('change',()=>setTimeout(applySpeed,0));++ // Show me: one run, every timer and frame of it kept so stopRun() ends it at once+ function running(){return runFrame!==0||runTimers.length>0}+ function stopRun(){cancelAnimationFrame(runFrame);runFrame=0;runTimers.forEach(clearTimeout);runTimers=[]}+ function later(fn,wait){const id=setTimeout(()=>{runTimers=runTimers.filter(t=>t!==id);fn()},wait);runTimers.push(id)}+ const ease=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2;+ // Scrolls the page to `to` over `time` ms; the position on each frame comes from the time since the start+ function glide(to,time,done){+ const from=scroller.scrollTop;let start=null;+ function step(now){+ if(start===null)start=now;+ const t=Math.min((now-start)/time,1);+ scroller.scrollTop=from+(to-from)*ease(t);+ runFrame=t<1?requestAnimationFrame(step):0;+ if(t>=1&&done)done();+ }+ runFrame=requestAnimationFrame(step);+ }+ // The page glides down one and a half boxes (up instead when there is no room below), holds, and glides back to where it+ // began. Under reduced motion it jumps instead: down, halfway back (where only "On any scroll up" brings the bar back), home.+ document.getElementById('btn-demo').addEventListener('click',()=>{+ const again=running(); // pressed during a run: it begins again from the same place+ stopRun();measure();+ const from=again?runFrom:scroller.scrollTop,span=Math.round(scroller.clientHeight*1.5);+ const far=from+span<=maxY?from+span:Math.max(0,from-span);+ runFrom=from;+ if(motionMQ.matches){+ scroller.scrollTop=far;+ later(()=>{scroller.scrollTop=Math.round((from+far)/2)},1000);+ later(()=>{scroller.scrollTop=from},2000);+ return;+ }+ glide(far,MOVE*slow(),()=>later(()=>glide(from,MOVE*slow()),HOLD));+ });+ // Reset: back to the top with the bar in place, at once+ document.getElementById('btn-reset').addEventListener('click',()=>{+ stopRun();+ bar.classList.add('snap');+ scroller.scrollTop=0;lastY=0;setAway(false);+ void bar.offsetWidth;+ bar.classList.remove('snap');+ });++ 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('speed-seg',d=>{ms=+d.ms;applySpeed()});+ choices('back-seg',d=>{comeBack=d.back});+ shrinkTog.addEventListener('change',()=>stage.classList.toggle('shrink',shrinkTog.checked));++ window.addEventListener('resize',measure);+ if(document.fonts&&document.fonts.ready)document.fonts.ready.then(measure);+ measure();applySpeed();+</script>+</body>+</html>diff --git a/animations/01-scroll-based/scroll-background-color/index.html b/animations/01-scroll-based/scroll-background-color/index.htmlindex d87bbdd5..1f436d02 100644--- a/animations/01-scroll-based/scroll-background-color/index.html+++ b/animations/01-scroll-based/scroll-background-color/index.html@@ -40,7 +40,7 @@<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="../scrollspy-nav/" rel="prev" aria-label="Previous: Scrollspy Navigation"><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>Scrollspy Navigation</span></a></span>+ <span class="hb-pager"><a href="../scrollspy-nav/" rel="prev" aria-label="Previous: Scrollspy Navigation"><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>Scrollspy Navigation</span></a><a href="../hide-on-scroll-header/" rel="next" aria-label="Next: Hide-on-Scroll Header"><span><span class="hb-dir">Next: </span>Hide-on-Scroll Header</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">diff --git a/index.html b/index.htmlindex e2d7eb15..d987f290 100644--- a/index.html+++ b/index.html@@ -525,6 +525,18 @@ button,input{font:inherit;color:inherit}.pv-zoom{background:#08090c;display:grid;place-items:center}.pv-zoom .img{width:82%;height:78%;border-radius:6px;background:conic-gradient(from 30deg,var(--accent),#12141a,var(--accent),#12141a,var(--accent));clip-path:inset(30% 32% round 6px);animation:zoomin 3.8s var(--ease) infinite}@keyframes zoomin{0%,14%{clip-path:inset(30% 32% round 6px)}68%,100%{clip-path:inset(0 0 round 6px)}}+/* a small page in a window: it scrolls down while its top bar slides away, holds, and scrolls back while the bar returns */+.pv-hideheader{background:#08090c}+.pv-hideheader .win{position:absolute;left:19%;right:19%;top:27%;bottom:-6%;overflow:hidden;border:1px solid #232830;border-bottom:0;border-radius:8px 8px 0 0;background:#0d0f14}+.pv-hideheader .pg{display:flex;flex-direction:column;gap:7px;padding:30% 9% 0;animation:hh-pg 4.4s cubic-bezier(.45,0,.3,1) infinite}+.pv-hideheader .pg b{flex:none;height:7px;border-radius:2px;background:#232830}+.pv-hideheader .pg .im{height:26px;border-radius:4px;background:color-mix(in srgb,var(--accent) 24%,#161a22)}+.pv-hideheader .bar{position:absolute;left:0;right:0;top:0;height:24%;display:flex;align-items:center;gap:7%;padding:0 8%;background:#1b1f28;border-bottom:1px solid #2c323e;animation:hh-bar 4.4s cubic-bezier(.3,.7,.3,1) infinite}+.pv-hideheader .bar .lg{flex:none;width:9%;aspect-ratio:1;border-radius:50%;background:var(--accent)}+.pv-hideheader .bar .nm{width:34%;height:5px;border-radius:2px;background:#5a6070}+.pv-hideheader .bar .mn{flex:none;margin-left:auto;width:9%;height:8px;background:linear-gradient(#5a6070 0 2px,transparent 2px 3px,#5a6070 3px 5px,transparent 5px 6px,#5a6070 6px)}+@keyframes hh-pg{0%,12%{transform:translateY(0)}40%,56%{transform:translateY(-34%)}86%,100%{transform:translateY(0)}}+@keyframes hh-bar{0%,16%{transform:translateY(0)}24%,58%{transform:translateY(-106%)}66%,100%{transform:translateY(0)}}/* ── bespoke: 02 Entrance & Exit ── */.pv-fade{background:#08090c;display:grid;place-items:center}@@ -1007,7 +1019,7 @@ button,input{font:inherit;color:inherit}<section class="wrap home-hero" aria-labelledby="hero-title"><span class="float fl1" aria-hidden="true"></span><span class="float fl2" aria-hidden="true"></span><span class="float fl3" aria-hidden="true"></span><span class="float fl4" aria-hidden="true"></span><span class="float fl5" aria-hidden="true"></span><span class="float fl6" aria-hidden="true"></span>- <p class="pill"><span class="pill-dot" aria-hidden="true"></span>129 free animations · no coding needed</p>+ <p class="pill"><span class="pill-dot" aria-hidden="true"></span>130 free animations · no coding needed</p><h1 class="h1" id="hero-title">What do you want to animate?</h1><p class="sub">Pick a place, or describe it in your own words. Every animation plays live, and each one comes with a ready-made prompt for your AI assistant.</p><form class="search" id="search-form" role="search" action="./" method="get">@@ -1064,8 +1076,8 @@ button,input{font:inherit;color:inherit}<p class="empty-s">Try a simpler word, or pick one of these:</p><p class="pop"><button type="button" data-q="fade in">fade in</button><button type="button" data-q="typing text">typing text</button><button type="button" data-q="loading spinner">loading spinner</button><button type="button" data-q="parallax">parallax</button><button type="button" data-q="confetti">confetti</button></p></div>- <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 129 animations</span><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M6 13l6 6 6-6"/></svg></button></div>- <noscript><p class="noscript">This page shows its animations with JavaScript. All 129 are still easy to reach: see the <a href="https://github.com/matinmonshizadeh/animation-handbook#categories">category list on GitHub</a> or the <a href="sitemap.xml">full sitemap</a>. Each demo is a page of its own under <code>/animations/<category>/<name>/</code>.</p></noscript>+ <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 130 animations</span><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M6 13l6 6 6-6"/></svg></button></div>+ <noscript><p class="noscript">This page shows its animations with JavaScript. All 130 are still easy to reach: see the <a href="https://github.com/matinmonshizadeh/animation-handbook#categories">category list on GitHub</a> or the <a href="sitemap.xml">full sitemap</a>. Each demo is a page of its own under <code>/animations/<category>/<name>/</code>.</p></noscript></section><section class="how" id="how" aria-labelledby="how-title">@@ -1083,7 +1095,7 @@ button,input{font:inherit;color:inherit}<footer class="wrap foot"><a class="brand" href="./"><svg class="mark" viewBox="0 0 32 32" aria-hidden="true"><circle class="ring" cx="11.16" cy="20.84" r="6.1"/><circle class="ring" cx="15.12" cy="16.88" r="6.1"/><circle class="ring" cx="18.51" cy="13.49" r="6.1"/><circle class="ball" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>- <p class="foot-t">129 web animations with live demos and copyable prompts.</p>+ <p class="foot-t">130 web animations with live demos and copyable prompts.</p><nav class="nav" aria-label="Footer"><a class="lnk" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener noreferrer">GitHub</a><a class="lnk" href="#top">Back to top</a></nav></footer><div class="toast" id="toast" role="status" aria-live="polite"><span class="ok" aria-hidden="true"><svg class="i" viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span><span class="toast-t"></span></div>@@ -1130,6 +1142,7 @@ const CATS=[['svg-line-draw','SVG Line Draw on Scroll','A line draws itself along a route as you scroll. Best for timelines.'],['scrollspy-nav','Scrollspy Navigation','A menu highlights the section you are reading. Best for long docs.'],['scroll-background-color','Scroll-Driven Background Color','The background color changes as you scroll through sections. Best for stories.'],+ ['hide-on-scroll-header','Hide-on-Scroll Header','The top bar slides away as you scroll down and comes back as you scroll up. Best for mobile pages.'],]},{@@ -1281,7 +1294,7 @@ const CATS=[const PV={'smooth-scroll':'smoothsc','text-fill-on-scroll':'txtfill','scroll-velocity-skew':'vskew',- 'svg-line-draw':'linedraw','scrollspy-nav':'spy','scroll-background-color':'bgblend',+ 'svg-line-draw':'linedraw','scrollspy-nav':'spy','scroll-background-color':'bgblend','hide-on-scroll-header':'hideheader','hamburger-menu-toggle':'hamb','theme-toggle-morph':'thememorph','copy-to-clipboard':'copyfx','star-rating':'stars','toast-notification':'toast','segmented-control':'segct','pull-to-refresh':'pullref','flip-card-3d':'flip3d','matrix-rain':'matrix','plasma':'plasmapv',@@ -1348,6 +1361,7 @@ const PLACES={'svg-line-draw':['scroll'],'scrollspy-nav':['scroll','menu'],'scroll-background-color':['scroll','bg'],+ 'hide-on-scroll-header':['menu','scroll'],// 02'fade-in-out':['intro'],'slide-in':['intro','menu','load'],@@ -1464,6 +1478,7 @@ const PICKS=['click-ripple','typewriter-effect','flip-card-3d','aurora','hamburgfunction pvMarkup(k){switch(k){case 'sig1': return '<div class="s1 anim">'+'<b></b>'.repeat(9)+'</div>';+ case 'hideheader': return '<span class="win"><span class="pg anim">'+[0,100,86,100,70,0,100,92,64,100,0,78,100,88].map(function(w){return w?'<b style="width:'+w+'%"></b>':'<b class="im"></b>';}).join('')+'</span><span class="bar anim"><span class="lg"></span><span class="nm"></span><span class="mn"></span></span></span>';case 'sig2': return '<span class="s2 anim"></span>';case 'sig3': return '<span class="s3 pa anim"></span><span class="s3 pb anim"></span>';case 'sig4': return '<span class="s4r anim"></span><span class="s4r r2 anim"></span><span class="s4r r3 anim"></span><span class="s4d"></span>';@@ -1746,7 +1761,7 @@ let shown=[];// under the place label or between two states). Nothing here runs without reduced motion.const STILL={cover:.1,curtain:.6,kinetic:.25,carousel:.1,typewriter:.55,textclip:.7,svgpath:.7,smoke:.3,leak:.7,- flash:.41,blurpage:.2,toggle:.7,shake:.8+ flash:.41,blurpage:.2,toggle:.7,shake:.8,hideheader:.72};function hold(card){const anims=card.querySelector('.pv').getAnimations({subtree:true});diff --git a/sitemap.xml b/sitemap.xmlindex 23cc35d9..24a843eb 100644--- a/sitemap.xml+++ b/sitemap.xml@@ -27,6 +27,7 @@<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/svg-line-draw/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/scrollspy-nav/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/scroll-background-color/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>+ <url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/hide-on-scroll-header/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/fade-in-out/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/slide-in/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/slide-up-reveal/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>