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 Parallax Depth-of-Field to the guided-steps page
matindeb1ad61ef9b
diff --git a/animations/01-scroll-based/parallax-depth-of-field/README.md b/animations/01-scroll-based/parallax-depth-of-field/README.mdindex d0b02926..61fce950 100644--- a/animations/01-scroll-based/parallax-depth-of-field/README.md+++ b/animations/01-scroll-based/parallax-depth-of-field/README.md@@ -4,10 +4,10 @@## What it is-Parallax depth-of-field combines two scroll-driven techniques: each layer of a-scene moves at a speed proportional to its perceived distance from the viewer-(parallax), and a virtual focal plane blurs every layer according to how far it-sits from the current focal depth. The result mimics a camera rack-focus pulled+Parallax depth-of-field combines two effects that follow the scroll. Each layer+of a scene moves by an amount that matches how near it is, and a point of sharp+focus travels from the farthest layer to the nearest, blurring every other layer+by how far it sits from that focus. The result looks like a camera pulling focusthrough a landscape as you scroll.## When to use it@@ -49,14 +49,13 @@ The loop only runs while the two values differ, so an idle page costs nothing.## Key parameters-| Parameter | Default | Effect |-|------------|---------|--------|-| `MAX_BLUR` | 14px | Maximum blur on a layer at full distance from focal plane |-| `depth` | 0.0–1.0 | Fixed depth per layer; 0 = far, 1 = near |-| `speed` | 0.0–0.70 | Fraction of `maxOffset` the layer travels over full scroll |-| `maxOffset`| 120px | Maximum translateY distance (applied at nearest layer) |-| `EASE` | 0.14 | Share of the remaining distance covered per frame. Lower = smoother but laggier; above ~0.3 the stepping returns |-| `BLUR_STEP`| 0.5px | Granularity the blur radius snaps to, so the compositor can reuse a cached texture |+| Parameter | Default | Effect |+|-----------|---------|--------|+| Focus | Follows the scroll | Sharp on the sky at the top of the scroll and on the front ridge at the end; each layer blurs by its distance from it |+| Strongest blur | 14px (8px on phones) | The blur of a layer as far from the focus as a layer can be |+| Layer travel | 19% of the box's height (12.5% on phones) | What the layers' sinking is measured against: over the whole scroll the front ridge sinks 70% of it, the hills 45%, the mountains 25%, the far peaks 10% and the sky not at all |+| Easing | 14% a frame | How much of the remaining distance the layers cover each frame; lower is smoother but lags more |+| Pinned scene | Three box heights of scrolling | How much scrolling the whole focus pull takes |## Production notes@@ -85,7 +84,5 @@ The loop only runs while the two values differ, so an idle page costs nothing.## See also-- [Parallax Scrolling](../parallax-scrolling/) — four SVG layers at different scroll speeds;- the speed-ratio depth concept without the focal-plane blur.-- [Reverse-Scrolling Columns](../reverse-scrolling-columns/) — takes speed-ratio- depth further by making columns scroll in opposite directions.+- [Parallax Scrolling](../parallax-scrolling/) — the same layered depth, without the blur+- [Reverse-Scrolling Columns](../reverse-scrolling-columns/) — columns move against each other as you scrolldiff --git a/animations/01-scroll-based/parallax-depth-of-field/index.html b/animations/01-scroll-based/parallax-depth-of-field/index.htmlindex 69eee41d..4ede4506 100644--- a/animations/01-scroll-based/parallax-depth-of-field/index.html+++ b/animations/01-scroll-based/parallax-depth-of-field/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Parallax Depth-of-Field — Animation Handbook</title>- <meta name="description" content="Five mountain layers translate at different speeds; a focal plane blurs each by its depth distance.">+ <meta name="description" content="Layers move at their own speed as the focus shifts. Best for cinematic intros."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/parallax-depth-of-field/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,203 +12,152 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Parallax Depth-of-Field — Animation Handbook">- <meta property="og:description" content="Five mountain layers translate at different speeds; a focal plane blurs each by its depth distance.">+ <meta property="og:description" content="Layers move at their own speed as the focus shifts. Best for cinematic intros."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/parallax-depth-of-field/"><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="Parallax Depth-of-Field — Animation Handbook">- <meta name="twitter:description" content="Five mountain layers translate at different speeds; a focal plane blurs each by its depth distance.">+ <meta name="twitter:description" content="Layers move at their own speed as the focus shifts. Best for cinematic intros."><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": "Parallax Depth-of-Field", "name": "Parallax Depth-of-Field", "description": "Five mountain layers translate at different speeds; a focal plane blurs each by its depth distance.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/parallax-depth-of-field/", "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, Parallax Depth-of-Field"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Parallax Depth-of-Field", "name": "Parallax Depth-of-Field", "description": "Layers move at their own speed as the focus shifts. Best for cinematic intros.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/parallax-depth-of-field/", "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, Parallax Depth-of-Field"}</script><style>- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-700.woff2') format('woff2');font-weight:700;font-display:swap}- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-800.woff2') format('woff2');font-weight:800;font-display:swap}- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-400.woff2') format('woff2');font-weight:400;font-display:swap}- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-500.woff2') format('woff2');font-weight:500;font-display:swap}- :root {- --bg: #0b0b0d;- --ui-bg: #111114;- --ui-border: rgba(255,255,255,.09);- --ui-accent: #6ea8ff;- --ui-text: #f4f4f2;- --ui-muted: #77777e;- --disp: 'Bricolage','Arial Narrow',sans-serif;- --mono: 'PlexMono',ui-monospace,Menlo,Consolas,monospace;- --stage-h: 620px;- }+ :root{--ui-accent:#6ea8ff}*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}- body{background:var(--bg);color:var(--ui-text);font-family:var(--mono);- -webkit-font-smoothing:antialiased;padding:clamp(12px,3vw,24px)}- header{margin-bottom:20px}- header h1{font-family:var(--disp);font-weight:700;font-size:clamp(16px,2.2vw,22px);letter-spacing:-.01em}- header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}-- .layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}-- .stage{- flex:1;min-width:0;height:var(--stage-h);- overflow-y:scroll;scrollbar-width:none;- border:1px solid var(--ui-border);border-radius:8px;- }+ .stage{position:relative;overflow-y:auto;scrollbar-width:none;container-type:size;background:#0b0b0d}.stage::-webkit-scrollbar{display:none}- .scene{height:calc(var(--stage-h) * 4)}- .pinned{position:sticky;top:0;height:var(--stage-h);overflow:hidden}-+ .scene{height:400cqh}+ .pinned{position:sticky;top:0;height:100cqh;overflow:hidden}.layer{position:absolute;top:0;left:0;width:100%;height:100%;/* promote for transform only — hinting `filter` keeps the blur pass hotand costs more memory than it saves */will-change:transform;transform:translate3d(0,0,0);}-- 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)}- .tbl .row.focused{color:var(--ui-accent)}- .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:40px;text-align:right;color:var(--ui-text)}- .hint{display:flex;justify-content:space-between;font-size:9px;color:var(--ui-muted);margin-top:-4px}- .div{height:1px;background:var(--ui-border)}-- @media(max-width:600px){- .layout{flex-direction:column}- aside{width:100%}- /* once the container is a column, `flex:1` makes flex-basis the *height*- and it would override --stage-h, stretching the stage to its content */- .stage{flex:none;width:100%}- :root{--stage-h:480px}- }@media(prefers-reduced-motion:reduce){.layer{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="../parallax-scrolling/" 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/parallax-depth-of-field/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>--<header>- <h1>Parallax Depth-of-Field</h1>- <p>Five mountain layers translate at different speeds; a focal plane blurs each by its depth distance.</p>-</header>--<div class="layout">- <div class="stage" id="stage">- <div class="scene">- <div class="pinned">-- <!-- L5: Sky + stars (depth 0.0, static) -->- <svg class="layer" id="l5" viewBox="0 0 1200 800"- preserveAspectRatio="xMidYMid slice" xmlns="http://www.w3.org/2000/svg">- <defs>- <linearGradient id="sky" x1="0" y1="0" x2="0" y2="1">- <stop offset="0%" stop-color="#141a24"/>- <stop offset="100%" stop-color="#0b0b0d"/>- </linearGradient>- </defs>- <rect width="1200" height="800" fill="url(#sky)"/>- <circle cx="80" cy="55" r="1.2" fill="#fff" opacity=".5"/>- <circle cx="210" cy="28" r="1" fill="#fff" opacity=".4"/>- <circle cx="345" cy="88" r=".9" fill="#fff" opacity=".6"/>- <circle cx="480" cy="18" r="1.3" fill="#fff" opacity=".3"/>- <circle cx="600" cy="52" r="1" fill="#fff" opacity=".5"/>- <circle cx="720" cy="33" r="1.1" fill="#fff" opacity=".4"/>- <circle cx="865" cy="14" r=".8" fill="#fff" opacity=".6"/>- <circle cx="950" cy="68" r="1.2" fill="#fff" opacity=".3"/>- <circle cx="1055" cy="40" r="1" fill="#fff" opacity=".5"/>- <circle cx="1150" cy="24" r=".9" fill="#fff" opacity=".4"/>- <circle cx="155" cy="118" r=".8" fill="#fff" opacity=".3"/>- <circle cx="395" cy="138" r="1" fill="#fff" opacity=".4"/>- <circle cx="672" cy="108" r=".9" fill="#fff" opacity=".5"/>- <circle cx="902" cy="128" r="1.1" fill="#fff" opacity=".3"/>- </svg>-- <!-- L4: Distant peaks (depth 0.2) -->- <svg class="layer" id="l4" viewBox="0 0 1200 800"- preserveAspectRatio="xMidYMid slice" xmlns="http://www.w3.org/2000/svg">- <polygon fill="#33455f"- points="0,500 80,340 180,400 300,280 420,360 540,260- 660,320 780,290 900,330 1020,270 1140,310 1200,290 1200,800 0,800"/>- </svg>-- <!-- L3: Mid mountains (depth 0.4) -->- <svg class="layer" id="l3" viewBox="0 0 1200 800"- preserveAspectRatio="xMidYMid slice" xmlns="http://www.w3.org/2000/svg">- <polygon fill="#253243"- points="0,530 100,390 220,440 360,320 480,400 600,310- 720,370 840,345 960,382 1080,332 1200,360 1200,800 0,800"/>- </svg>-- <!-- L2: Near hills (depth 0.7) -->- <svg class="layer" id="l2" viewBox="0 0 1200 800"- preserveAspectRatio="xMidYMid slice" xmlns="http://www.w3.org/2000/svg">- <polygon fill="#18202c"- points="0,570 120,445 260,480 400,392 540,455 680,382- 820,432 960,408 1100,442 1200,422 1200,800 0,800"/>- </svg>-- <!-- L1: Foreground (depth 1.0) -->- <svg class="layer" id="l1" viewBox="0 0 1200 800"- preserveAspectRatio="xMidYMid slice" xmlns="http://www.w3.org/2000/svg">- <polygon fill="#0e1015"- points="0,612 160,502 320,542 480,472 640,522 800,482- 960,522 1120,492 1200,508 1200,800 0,800"/>- </svg>-+<body class="hb" data-hb-kind="scroll" data-hb-autoplay>+<nav class="hb-bar" aria-label="Animation Handbook">+ <a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>+ <span class="hb-pager"><a href="../parallax-scrolling/" rel="next" aria-label="Next: Parallax Scrolling"><span><span class="hb-dir">Next: </span>Parallax Scrolling</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.01 · Scroll-Based</p>+ <h1>Parallax Depth-of-Field</h1>+ <p class="hb-lede">Layers move at their own speed as the focus shifts. Best for cinematic intros.</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="Mountain layers that move and blur as you scroll">+ <div class="scene">+ <div class="pinned">++ <!-- L5: Sky + stars (depth 0.0, static) -->+ <svg class="layer" id="l5" viewBox="0 0 1200 800" preserveAspectRatio="none" aria-hidden="true" xmlns="http://www.w3.org/2000/svg">+ <defs>+ <linearGradient id="sky" x1="0" y1="0" x2="0" y2="1">+ <stop offset="0%" stop-color="#141a24"/>+ <stop offset="100%" stop-color="#0b0b0d"/>+ </linearGradient>+ </defs>+ <rect width="1200" height="800" fill="url(#sky)"/>+ <circle cx="80" cy="55" r="1.2" fill="#fff" opacity=".5"/>+ <circle cx="210" cy="28" r="1" fill="#fff" opacity=".4"/>+ <circle cx="345" cy="88" r=".9" fill="#fff" opacity=".6"/>+ <circle cx="480" cy="18" r="1.3" fill="#fff" opacity=".3"/>+ <circle cx="600" cy="52" r="1" fill="#fff" opacity=".5"/>+ <circle cx="720" cy="33" r="1.1" fill="#fff" opacity=".4"/>+ <circle cx="865" cy="14" r=".8" fill="#fff" opacity=".6"/>+ <circle cx="950" cy="68" r="1.2" fill="#fff" opacity=".3"/>+ <circle cx="1055" cy="40" r="1" fill="#fff" opacity=".5"/>+ <circle cx="1150" cy="24" r=".9" fill="#fff" opacity=".4"/>+ <circle cx="155" cy="118" r=".8" fill="#fff" opacity=".3"/>+ <circle cx="395" cy="138" r="1" fill="#fff" opacity=".4"/>+ <circle cx="672" cy="108" r=".9" fill="#fff" opacity=".5"/>+ <circle cx="902" cy="128" r="1.1" fill="#fff" opacity=".3"/>+ </svg>++ <!-- L4: Distant peaks (depth 0.2) -->+ <svg class="layer" id="l4" viewBox="0 0 1200 800" preserveAspectRatio="none" aria-hidden="true" xmlns="http://www.w3.org/2000/svg">+ <polygon fill="#33455f"+ points="0,500 80,340 180,400 300,280 420,360 540,260+ 660,320 780,290 900,330 1020,270 1140,310 1200,290 1200,800 0,800"/>+ </svg>++ <!-- L3: Mid mountains (depth 0.4) -->+ <svg class="layer" id="l3" viewBox="0 0 1200 800" preserveAspectRatio="none" aria-hidden="true" xmlns="http://www.w3.org/2000/svg">+ <polygon fill="#253243"+ points="0,530 100,390 220,440 360,320 480,400 600,310+ 720,370 840,345 960,382 1080,332 1200,360 1200,800 0,800"/>+ </svg>++ <!-- L2: Near hills (depth 0.7) -->+ <svg class="layer" id="l2" viewBox="0 0 1200 800" preserveAspectRatio="none" aria-hidden="true" xmlns="http://www.w3.org/2000/svg">+ <polygon fill="#18202c"+ points="0,570 120,445 260,480 400,392 540,455 680,382+ 820,432 960,408 1100,442 1200,422 1200,800 0,800"/>+ </svg>++ <!-- L1: Foreground (depth 1.0) -->+ <svg class="layer" id="l1" viewBox="0 0 1200 800" preserveAspectRatio="none" aria-hidden="true" xmlns="http://www.w3.org/2000/svg">+ <polygon fill="#0e1015"+ points="0,612 160,502 320,542 480,472 640,522 800,482+ 960,522 1120,492 1200,508 1200,800 0,800"/>+ </svg>++ </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>- </div>- </div>+ </section>- <aside>- <p class="note">Every layer sits at a fixed depth. The focal plane is one 0–1 value, and a layer's blur is simply its distance from that plane — so racking focus from the far sky to the near ridge is a single number changing.</p>- <div>- <div class="lbl">Scroll Progress</div>- <div class="row"><span>Progress</span><span class="v" id="progress">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">2</span>+ <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div></div>- <div class="div"></div>- <div>- <div class="lbl" id="focal-label">Focal Plane</div>- <div class="sr">- <input type="range" id="focalSlider" aria-labelledby="focal-label" min="0" max="100" value="0">- <span class="sv" id="focal-val">0.00</span>+ <div class="hb-card">+ <p class="hb-prompt">Add a parallax depth-of-field effect to [your layered scene or illustration]. Split the scene into layers from far to near and hold it in place while the visitor scrolls through a taller section. As they scroll, move each layer by an amount that grows with its nearness, and move a point of sharp focus from the farthest layer to the nearest: blur each layer by how far it sits from that focus. Ease the layers toward the scroll position on every frame, so a mouse wheel's jumps turn into smooth movement. If the visitor has reduced motion turned on, keep the layers still and only shift the focus.</p>+ <div class="hb-chips-box" hidden>+ <p class="hb-chips-title">Your settings</p>+ <ul class="hb-chips"></ul></div>- <div class="hint"><span>far</span><span>near</span></div>- </div>- <div class="div"></div>- <div>- <div class="lbl">Blur</div>- <div class="tbl" id="readout">- <div class="row" id="row-l5"><span>L5 · sky</span><span class="v">0px</span></div>- <div class="row" id="row-l4"><span>L4 · peaks</span><span class="v">0px</span></div>- <div class="row" id="row-l3"><span>L3 · mountains</span><span class="v">0px</span></div>- <div class="row" id="row-l2"><span>L2 · hills</span><span class="v">0px</span></div>- <div class="row" id="row-l1"><span>L1 · ridge</span><span class="v">0px</span></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 scene.</p></div></div>- </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>Hero scenes</li><li>Story intros</li><li>Illustrated landscapes</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Large photos</li><li>Text-heavy pages</li></ul>+ </div>+ </section>++ <section class="hb-related" aria-labelledby="hb-related-title" hidden>+ <h2 id="hb-related-title">Similar animations</h2>+ <div class="hb-rel-list"></div>+ </section>+</main>+<footer class="hb-foot"><span>Animation Handbook</span><a href="#top">Back to top ↑</a></footer><script>const LAYERS = [{ el: document.getElementById('l5'), depth: 0.0, speed: 0.00 },@@ -217,18 +166,7 @@ body{padding-top:46px}{ el: document.getElementById('l2'), depth: 0.7, speed: 0.45 },{ el: document.getElementById('l1'), depth: 1.0, speed: 0.70 },];- const ROWS = [- document.getElementById('row-l5'),- document.getElementById('row-l4'),- document.getElementById('row-l3'),- document.getElementById('row-l2'),- document.getElementById('row-l1'),- ];- const slider = document.getElementById('focalSlider');const stage = document.getElementById('stage'); // the demo's own scroll container- const progressEl = document.getElementById('progress');- const focalEl = document.getElementById('focal-val');- const VALUES = ROWS.map(r => r.querySelector('.v'));const reduceMQ = window.matchMedia('(prefers-reduced-motion: reduce)');let reduced = reduceMQ.matches;@@ -241,27 +179,24 @@ body{padding-top:46px}// Layout reads live here only — never in the scroll handler, where each one// would force a synchronous reflow before the styles below are written.function measure() {- const mobile = window.innerWidth <= 600;- MAX_BLUR = mobile ? 8 : 14;- MAX_OFFSET = mobile ? 60 : 120;+ // A phone, held upright or sideways, gets the smaller blur and travel+ const phone = window.innerWidth <= 600 || window.innerHeight <= 500;+ MAX_BLUR = phone ? 8 : 14;+ MAX_OFFSET = stage.clientHeight * (phone ? 0.125 : 0.19);maxScroll = Math.max(1, stage.scrollHeight - stage.clientHeight);}- let target = 0, current = 0, raf = null, manual = false;- let lastFocus = -1, lastSlider = -1, lastPct = -1;+ let target = 0, current = 0, raf = null;const lastBlur = LAYERS.map(() => -1), lastOffset = LAYERS.map(() => NaN);function render(f) {- let idx = 0, best = Infinity;for (let i = 0; i < LAYERS.length; i++) {const layer = LAYERS[i], dist = Math.abs(layer.depth - f);- if (dist < best) { best = dist; idx = i; }// Snapping blur to 0.5px steps lets the compositor reuse the blurred texture// instead of re-rasterising five full-screen layers on every single frame.const blur = Math.round(MAX_BLUR * dist / BLUR_STEP) * BLUR_STEP;if (blur !== lastBlur[i]) {layer.el.style.filter = blur > 0 ? `blur(${blur}px)` : 'none';- VALUES[i].textContent = `${blur}px`;lastBlur[i] = blur;}const offset = reduced ? 0 : layer.speed * f * MAX_OFFSET;@@ -270,12 +205,6 @@ body{padding-top:46px}lastOffset[i] = offset;}}- if (idx !== lastFocus) {- for (let i = 0; i < ROWS.length; i++) ROWS[i].classList.toggle('focused', i === idx);- lastFocus = idx;- }- const pct = Math.round(f * 100);- if (pct !== lastPct) { progressEl.textContent = `${pct}%`; focalEl.textContent = f.toFixed(2); lastPct = pct; }}function tick() {@@ -292,17 +221,11 @@ body{padding-top:46px}}function onScroll() {- if (manual) return;target = Math.min(1, Math.max(0, stage.scrollTop / maxScroll));- const v = Math.round(target * 100);- if (v !== lastSlider) { slider.value = v; lastSlider = v; }schedule();}- slider.addEventListener('input', () => {- manual = true; lastSlider = +slider.value; target = slider.value / 100; schedule();- });- stage.addEventListener('scroll', () => { manual = false; onScroll(); }, { passive: true });+ stage.addEventListener('scroll', onScroll, { passive: true });let rt;window.addEventListener('resize', () => {@@ -316,9 +239,7 @@ body{padding-top:46px}// Seed from wherever the stage actually starts — no fly-in on load.measure();target = current = Math.min(1, Math.max(0, stage.scrollTop / maxScroll));- slider.value = lastSlider = Math.round(target * 100);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 4d518cf1..a9e8e0d1 100644--- a/index.html+++ b/index.html@@ -879,7 +879,7 @@ const CATS=[desc:'Animations driven by scroll position — parallax, sticky, scrub, snap, and narrative storytelling.',folder:'animations/01-scroll-based',entries:[- ['parallax-depth-of-field','Parallax Depth-of-Field','Five mountain layers translate at different speeds; blur simulates camera depth-of-field.'],+ ['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','Elements move at different speeds — background slower, foreground faster — creating a 3D depth illusion.'],['reverse-scrolling-columns','Reverse-Scrolling Columns','A center column scrolls normally while two flanking columns scroll in reverse, looping infinitely.'],['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.'],