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 Scroll Velocity Skew to the guided-steps page
matin995b553b8f47
diff --git a/animations/01-scroll-based/scroll-velocity-skew/README.md b/animations/01-scroll-based/scroll-velocity-skew/README.mdindex ecd594a0..d2856aba 100644--- a/animations/01-scroll-based/scroll-velocity-skew/README.md+++ b/animations/01-scroll-based/scroll-velocity-skew/README.md@@ -2,7 +2,7 @@## What it is-A distortion effect where content shears in proportion to how *fast* the user is scrolling, not where they are on the page. Scroll quickly and rows of content skew a few degrees in the direction of travel; stop scrolling and the smoothed velocity decays to zero, so the shear relaxes back to straight on its own. It is the signature move of Locomotive Scroll-era portfolio sites, and it is this handbook's only entry driven by scroll velocity rather than scroll position.+Scroll velocity skew leans content by how fast you scroll, not by where you are. Scroll quickly and the rows tilt in the direction of travel; stop and they spring back straight. It makes scrolling feel physical, as if the content bends under its own momentum.## When to use it@@ -13,29 +13,31 @@ A distortion effect where content shears in proportion to how *fast* the user is## How it works-Every technique elsewhere in this section maps scroll **position** to animation progress. This one maps scroll **velocity**: the per-frame difference in `scrollTop`. The raw delta is noisy and spiky, so it is smoothed with a lerp before being scaled and clamped into a skew angle:+Every technique elsewhere in this section maps scroll **position** to animation progress. This one maps scroll **velocity**: the change in `scrollTop` from one frame to the next, counted per sixtieth of a second. The raw delta is noisy and spiky, so it is smoothed with a lerp before being scaled and clamped into a skew angle:```js-function tick() {- const raw = el.scrollTop - lastTop; // px moved since last frame+function tick(now) {+ const dt = lastTime ? Math.min(Math.max(now - lastTime, 1), 50) : FRAME; // ms since the last frame+ lastTime = now;+ const raw = (el.scrollTop - lastTop) * FRAME / dt; // px moved per 1/60 slastTop = el.scrollTop;- vel += (raw - vel) * SMOOTH; // low-pass filter the spikes+ vel += (raw - vel) * (1 - Math.pow(1 - SMOOTH, dt / FRAME)); // low-pass filter the spikesconst skew = clamp(vel * INTENSITY, -MAX, MAX);rows.forEach(r => r.style.transform = `skewY(${skew}deg)`);requestAnimationFrame(tick);}```-The smoothing is what makes the effect feel physical. Raw deltas would snap the skew on and off with every wheel notch; the lerp turns them into a value with inertia, so the shear ramps up as you accelerate and eases back down after you stop — a spring-back you get for free, without writing any spring code. The loop only runs while there is motion: when the smoothed velocity falls below a threshold and no new scroll event has arrived, it writes an identity transform and parks itself until the next scroll.+The smoothing is what makes the effect feel physical. Raw deltas would snap the skew on and off with every wheel notch; the lerp turns them into a value with inertia, so the shear ramps up as you accelerate and eases back down after you stop — a spring-back you get for free, without writing any spring code. The loop only runs while there is motion: when the smoothed velocity falls below a threshold and no new scroll event has arrived, it writes an identity transform and parks itself until the next scroll. Speed is measured per sixtieth of a second (`FRAME` is 1000/60 ms), so a 120Hz screen leans as much as a 60Hz one. Back to top, and Play starting again from the top, move the box in a single frame; when either button is clicked the demo takes the box's new position as its starting point, so that jump does not count as speed. A run of scrolling starts the same way, from where the box was before its first move, so even a single notch of the wheel leans the rows.## Key parameters-| Parameter | Default | What it does |-|-----------|---------|--------------|-| `INTENSITY` | 0.35 | Degrees of skew per px/frame of smoothed velocity — the overall strength |-| `MAX` | 12° | Clamp on the skew angle; keeps a fast flick from folding the layout in half |-| `SMOOTH` | 0.12 | Lerp factor for the velocity filter; lower = heavier, longer settle, higher = twitchier |-| Axis | `skewY` | `skewY` shears rows vertically (the classic look); `skewX` slants them sideways |+| Parameter | Default | Effect |+|-----------|---------|--------|+| Strength | Normal | How far the rows lean for a given scroll speed: subtle is 0.2°, normal 0.35° and strong 0.6° for each pixel scrolled in a sixtieth of a second |+| Lean | Tilt | Tilt tips each row like a slope, the classic look; Slant leans it sideways like italic text |+| Spring back | Normal | How quickly the lean follows the scroll speed and fades after you stop; slow feels heavy, quick feels twitchy |+| Most it leans | Medium | The largest angle allowed: 6°, 12° or 20°, so a fast flick cannot fold the rows over |## Production notes@@ -47,6 +49,6 @@ The smoothing is what makes the effect feel physical. Raw deltas would snap the## See also-- [Smooth (Inertia) Scroll](../smooth-scroll/) — the lerp-toward-target loop this effect usually rides on-- [Scrub Animation](../scrub-animation/) — the position-mapped counterpart: deterministic, reversible progress-- [Marquee Ticker](../../05-text-typography/marquee-ticker/) — often paired with velocity skew, with scroll speed modulating ticker speed+- [Smooth (Inertia) Scroll](../smooth-scroll/) — scrolling that glides to a stop, often paired with this effect+- [Scrub Animation](../scrub-animation/) — movement tied to where you are, not how fast you go+- [Marquee / Ticker](../../05-text-typography/marquee-ticker/) — text that scrolls sideways forever, often sped up by scrollingdiff --git a/animations/01-scroll-based/scroll-velocity-skew/index.html b/animations/01-scroll-based/scroll-velocity-skew/index.htmlindex 825e7458..f34ce243 100644--- a/animations/01-scroll-based/scroll-velocity-skew/index.html+++ b/animations/01-scroll-based/scroll-velocity-skew/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Scroll Velocity Skew — Animation Handbook</title>- <meta name="description" content="Rows shear in proportion to how fast you scroll — velocity, not position, drives the transform, so stopping lets everything spring back straight.">+ <meta name="description" content="Rows lean when you scroll fast and straighten when you stop. Best for galleries."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/scroll-velocity-skew/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,126 +12,162 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Scroll Velocity Skew — Animation Handbook">- <meta property="og:description" content="Rows shear in proportion to how fast you scroll — velocity, not position, drives the transform, so stopping lets everything spring back straight.">+ <meta property="og:description" content="Rows lean when you scroll fast and straighten when you stop. Best for galleries."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/scroll-velocity-skew/"><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="Scroll Velocity Skew — Animation Handbook">- <meta name="twitter:description" content="Rows shear in proportion to how fast you scroll — velocity, not position, drives the transform, so stopping lets everything spring back straight.">+ <meta name="twitter:description" content="Rows lean when you scroll fast and straighten when you stop. Best for galleries."><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": "Scroll Velocity Skew", "name": "Scroll Velocity Skew", "description": "Rows shear in proportion to how fast you scroll — velocity, not position, drives the transform, so stopping lets everything spring back straight.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/scroll-velocity-skew/", "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, Scroll Velocity Skew"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Scroll Velocity Skew", "name": "Scroll Velocity Skew", "description": "Rows lean when you scroll fast and straighten when you stop. Best for galleries.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/scroll-velocity-skew/", "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, Scroll Velocity Skew"}</script><style>- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-700.woff2') format('woff2');font-weight:700;font-display:swap}- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-800.woff2') format('woff2');font-weight:800;font-display:swap}- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-400.woff2') format('woff2');font-weight:400;font-display:swap}- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-500.woff2') format('woff2');font-weight:500;font-display:swap}- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#6ea8ff;--ui-text:#f4f4f2;--ui-muted:#77777e;--stage-h:620px;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace}+ :root{--ui-accent:#6ea8ff;--ui-border:rgba(255,255,255,.09)}*,*::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;background:var(--ui-bg)}+ .stage{position:relative;overflow-y:auto;scrollbar-width:none;background:#111114}.stage::-webkit-scrollbar{display:none}- .content{padding:clamp(16px,3vw,32px);display:flex;flex-direction:column;gap:clamp(14px,2vw,22px)}+ /* overflow:clip keeps a leaning row from making the box scrollable sideways or taller while it leans */+ .content{padding:clamp(16px,3vw,32px);display:flex;flex-direction:column;gap:clamp(14px,2vw,22px);overflow:clip}.row{display:flex;gap:clamp(10px,2vw,18px);align-items:center;padding:clamp(10px,1.6vw,16px);background:rgba(255,255,255,.03);border:1px solid var(--ui-border);border-radius:8px;will-change:transform}.thumb{flex-shrink:0;width:clamp(72px,14vw,120px);aspect-ratio:4/3;border-radius:6px}.meta{min-width:0;flex:1}- .m-title{font-family:var(--disp);font-weight:700;font-size:clamp(13px,1.8vw,17px);margin-bottom:8px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}+ .m-title{font-weight:700;font-size:clamp(13px,1.8vw,17px);margin-bottom:8px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.m-line{height:7px;border-radius:4px;background:rgba(255,255,255,.08);margin-top:6px}.m-line.short{width:62%}- .m-tag{font-size:10px;color:var(--ui-muted);margin-top:8px;letter-spacing:.5px}- 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:12px}- .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)}- .sr{display:flex;flex-direction:column;gap:4px}- .sr .row2{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}- .sr .row2 .v{color:var(--ui-text)}- input[type=range]{width:100%;min-height:44px;accent-color:var(--ui-accent);cursor:pointer}- .seg{display:flex;gap:6px}- .seg button{flex:1;min-height:44px;font:inherit;font-size:11px;color:var(--ui-muted);background:none;border:1px solid var(--ui-border);border-radius:6px;cursor:pointer}- .seg button[aria-pressed="true"]{color:var(--ui-text);border-color:var(--ui-accent);background:rgba(110,168,255,.08)}- .div{height:1px;background:var(--ui-border)}- .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}- .kv .v{color:var(--ui-text);font-variant-numeric:tabular-nums}- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}.stage{flex:none;width:100%}:root{--stage-h:480px}}</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="../text-fill-on-scroll/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../svg-line-draw/" 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/scroll-velocity-skew/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>-<header>- <h1>Scroll Velocity Skew</h1>- <p>Rows shear in proportion to how fast you scroll — velocity, not position, drives the transform, so stopping lets everything spring back straight.</p>-</header>-<div class="layout">- <div class="stage" id="stage"><div class="content" id="content"></div></div>- <aside>- <p class="note" id="note">Skew is mapped to smoothed scroll velocity, not scroll position. Scroll fast and the rows shear; the moment you stop, velocity decays to zero and the shear relaxes away.</p>- <div class="lbl">Intensity</div>- <div class="sr">- <input type="range" id="intensity" min="0.1" max="0.8" step="0.05" value="0.35">- <div class="row2"><span>deg per px/f</span><span class="v" id="intensityVal">0.35</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="../text-fill-on-scroll/" rel="prev" aria-label="Previous: Text Fill on Scroll"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Text Fill on Scroll</span></a><a href="../svg-line-draw/" rel="next" aria-label="Next: SVG Line Draw on Scroll"><span><span class="hb-dir">Next: </span>SVG Line Draw on Scroll</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>+</nav>+<main class="hb-page">+ <header class="hb-head">+ <p class="hb-cat">01.23 · Scroll-Based</p>+ <h1>Scroll Velocity Skew</h1>+ <p class="hb-lede">Rows lean when you scroll fast and straighten when you stop. Best for galleries.</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 fast inside the box and stop, or press Play and it scrolls for you.</p></div>+ </div>+ <div class="stage" id="stage" tabindex="0" role="region" aria-label="Rows that lean as you scroll">+ <div class="content" id="content"></div>+ </div>+ <div class="hb-player">+ <button class="hb-play" type="button" id="btn-scroll" data-hb-autoscroll><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M19 12l-7 7-7-7"/></svg>Play</button>+ <button class="hb-play" type="button" id="btn-top" data-hb-top><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 19V5M5 12l7-7 7 7"/></svg>Back to top</button>+ </div>+ </section>++ <section class="hb-step hb-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="str-lbl">Strength</p>+ <div class="seg" id="str-seg" role="group" aria-labelledby="str-lbl">+ <button type="button" data-k="0.2" aria-pressed="false">Subtle</button>+ <button type="button" data-k="0.35" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-k="0.6" aria-pressed="false">Strong</button>+ </div>+ <p class="hb-hint">How far the rows lean for the same scroll speed.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="lean-lbl">Lean</p>+ <div class="seg" id="lean-seg" role="group" aria-labelledby="lean-lbl">+ <button type="button" data-axis="skewY" class="on" aria-pressed="true">Tilt</button>+ <button type="button" data-axis="skewX" aria-pressed="false">Slant</button>+ </div>+ <p class="hb-hint">Tilt tips each row; Slant leans it like italics.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="spring-lbl">Spring back</p>+ <div class="seg" id="spring-seg" role="group" aria-labelledby="spring-lbl">+ <button type="button" data-s="0.07" aria-pressed="false">Slow</button>+ <button type="button" data-s="0.12" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-s="0.2" aria-pressed="false">Quick</button>+ </div>+ <p class="hb-hint">How quickly the rows react and straighten again.</p>+ </div></div>- <div class="lbl">Max skew</div>- <div class="sr">- <input type="range" id="maxSkew" min="4" max="20" step="1" value="12">- <div class="row2"><span>clamp</span><span class="v" id="maxSkewVal">12°</span></div>+ <details class="hb-options">+ <summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="max-lbl">Most it leans</p>+ <div class="seg" id="max-seg" role="group" aria-labelledby="max-lbl">+ <button type="button" data-max="6" aria-pressed="false">Small</button>+ <button type="button" data-max="12" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-max="20" aria-pressed="false">Large</button>+ </div>+ <p class="hb-hint">A limit, so a hard flick cannot fold the rows over.</p>+ </div>+ </div>+ </details>+ </section>++ <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">3</span>+ <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div></div>- <div class="lbl">Smoothing</div>- <div class="sr">- <input type="range" id="smooth" min="0.05" max="0.3" step="0.01" value="0.12">- <div class="row2"><span>lerp factor</span><span class="v" id="smoothVal">0.12</span></div>+ <div class="hb-card">+ <p class="hb-prompt">Add a velocity skew to [the rows or cards in your list or gallery]. Measure how far the list scrolls on each frame, smooth that speed so it rises and falls gradually, and lean every row by an angle in proportion to it, up to a limit. Fast scrolling leans the rows; when the scrolling stops, the speed falls to zero and they spring back straight. Lean each row on its own rather than the whole list, and stop the frame loop once everything is still. This effect can make some people feel unwell, so if the visitor has reduced motion turned on, keep the rows straight and scroll normally. 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>- <div class="lbl">Axis</div>- <div class="seg">- <button type="button" id="axisY" aria-pressed="true">skewY</button>- <button type="button" id="axisX" aria-pressed="false">skewX</button>+ </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="div"></div>- <div class="lbl">Live values</div>- <div class="kv"><span>Velocity</span><span class="v" id="velVal">+0.0 px/f</span></div>- <div class="kv"><span>Skew</span><span class="v" id="skewVal">0.00°</span></div>- <div class="kv"><span>Direction</span><span class="v" id="dirVal">·</span></div>- <div class="kv"><span>Position</span><span class="v" id="posVal">0%</span></div>- </aside>-</div>+ <div class="hb-fit">+ <h2>Good for</h2>+ <ul class="hb-tags hb-good"><li>Galleries</li><li>Portfolios</li><li>Project lists</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Reading content</li><li>Forms</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'),content=document.getElementById('content');- const velVal=document.getElementById('velVal'),skewVal=document.getElementById('skewVal'),dirVal=document.getElementById('dirVal'),posVal=document.getElementById('posVal');- const note=document.getElementById('note');const clamp=(v,a,b)=>Math.min(Math.max(v,a),b);- // Build ~14 media-card-like rows: gradient thumbnail + placeholder text lines.+ // Build 28 media-card-like rows: gradient thumbnail + placeholder text lines.const rows=[];const NAMES=['Signal','Drift','Cascade','Vector','Halide','Meridian','Pulse','Strata','Kelvin','Orbit','Fathom','Relay','Cinder','Apex'];- for(let i=0;i<14;i++){+ for(let i=0;i<28;i++){const hue=(210+i*22)%360;const el=document.createElement('div');el.className='row';el.innerHTML=`<div class="thumb" style="background:linear-gradient(135deg,hsl(${hue} 45% 42%),hsl(${(hue+40)%360} 55% 22%))"></div>`+- `<div class="meta"><div class="m-title">${String(i+1).padStart(2,'0')} — ${NAMES[i]}</div>`+- `<div class="m-line"></div><div class="m-line short"></div><div class="m-tag">scroll to shear</div></div>`;+ `<div class="meta"><div class="m-title">${String(i+1).padStart(2,'0')} — ${NAMES[i%14]}</div>`++ `<div class="m-line"></div><div class="m-line short"></div></div>`;content.appendChild(el);rows.push(el);}+ const FRAME=1000/60; // speed is counted per 1/60 s, so a 120Hz screen leans the samelet INTENSITY=0.35,MAX=12,SMOOTH=0.12,axis='skewY';- let vel=0,lastTop=stage.scrollTop,lastSkew=0,running=false,scrolled=false,maxScroll=1,reduce=false;-- // Layout reads live here only — never in the scroll handler.- function measure(){maxScroll=Math.max(1,stage.scrollHeight-stage.clientHeight);}+ let vel=0,lastTop=stage.scrollTop,seenTop=lastTop,lastTime=0,lastSkew=0,running=false,scrolled=false,reduce=false;function applySkew(deg){const r=Math.round(deg*100)/100;@@ -141,18 +177,15 @@ body{padding-top:46px}for(const el of rows)el.style.transform=t;}- function tick(){+ function tick(now){const top=stage.scrollTop;- const raw=top-lastTop;lastTop=top; // px moved this frame- vel+=(raw-vel)*SMOOTH; // lerp-smooth the raw delta+ const dt=lastTime?Math.min(Math.max(now-lastTime,1),50):FRAME;+ lastTime=now;+ const raw=(top-lastTop)*FRAME/dt;lastTop=top; // px moved per 1/60 s+ vel+=(raw-vel)*(1-Math.pow(1-SMOOTH,dt/FRAME)); // lerp-smooth the raw speed, the same at any frame rateapplySkew(reduce?0:clamp(vel*INTENSITY,-MAX,MAX));- velVal.textContent=(vel<0?'−':'+')+Math.abs(vel).toFixed(1)+' px/f';- skewVal.textContent=lastSkew.toFixed(2)+'°';- dirVal.textContent=Math.abs(vel)<0.05?'·':(vel>0?'↓':'↑');- posVal.textContent=Math.round(top/maxScroll*100)+'%';if(Math.abs(vel)<0.01&&!scrolled){ // settled: park the loopvel=0;applySkew(0);- velVal.textContent='+0.0 px/f';skewVal.textContent='0.00°';dirVal.textContent='·';running=false;return;}scrolled=false;@@ -161,34 +194,39 @@ body{padding-top:46px}stage.addEventListener('scroll',()=>{scrolled=true;- if(!running){running=true;lastTop=stage.scrollTop;requestAnimationFrame(tick);}+ // A run starts from where the box was before this move, so a single notch of the wheel counts as speed too.+ // Its first frame counts as 1/60 s: a frame's timestamp can be earlier than this moment.+ if(!running){running=true;lastTop=seenTop;lastTime=0;requestAnimationFrame(tick);}+ seenTop=stage.scrollTop;},{passive:true});+ // Back to top, and Play starting again from the top, move the box in one frame (the shared script does it while the click+ // is handled, before the click reaches the document). Taking the new place as where the box was makes that jump no speed.+ document.addEventListener('click',e=>{if(e.target.closest('#btn-top,#btn-scroll'))lastTop=seenTop=stage.scrollTop});- const rangeIds=[['intensity','intensityVal',v=>{INTENSITY=v;return v.toFixed(2)}],- ['maxSkew','maxSkewVal',v=>{MAX=v;return v+'°'}],- ['smooth','smoothVal',v=>{SMOOTH=v;return v.toFixed(2)}]];- for(const[id,out,set]of rangeIds){- const inp=document.getElementById(id),lab=document.getElementById(out);- inp.addEventListener('input',()=>{lab.textContent=set(parseFloat(inp.value));});- }- const axisY=document.getElementById('axisY'),axisX=document.getElementById('axisX');function setAxis(a){- axis=a;axisY.setAttribute('aria-pressed',a==='skewY');axisX.setAttribute('aria-pressed',a==='skewX');+ axis=a;lastSkew=NaN;applySkew(reduce?0:clamp(vel*INTENSITY,-MAX,MAX));}- axisY.addEventListener('click',()=>setAxis('skewY'));- axisX.addEventListener('click',()=>setAxis('skewX'));+ 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('str-seg',d=>{INTENSITY=+d.k});+ choices('lean-seg',d=>setAxis(d.axis));+ choices('spring-seg',d=>{SMOOTH=+d.s});+ choices('max-seg',d=>{MAX=+d.max});++ // Reduced motion: the rows stay straight however fast the box scrolls, and stop leaning at once if it turns on mid-visit.const rmq=window.matchMedia('(prefers-reduced-motion: reduce)');function onReduce(){reduce=rmq.matches;- if(reduce){vel=0;lastSkew=NaN;applySkew(0);note.textContent='Reduced motion is on: scrolling stays normal but the skew is held at 0°. Velocity-driven shear is exactly the kind of motion this preference exists to suppress.';}+ if(reduce){vel=0;lastSkew=NaN;applySkew(0);}}rmq.addEventListener('change',onReduce);onReduce();-- let rt;window.addEventListener('resize',()=>{clearTimeout(rt);rt=setTimeout(measure,150);});- measure();</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 2dcb906a..04d3a9c6 100644--- a/index.html+++ b/index.html@@ -901,7 +901,7 @@ const CATS=[['scroll-image-sequence','Scroll Image Sequence','Scrolling plays a series of pictures like a flip-book. Best for products.'],['smooth-scroll','Smooth (Inertia) Scroll','Scrolling glides to a stop instead of jumping. Best for portfolio sites.'],['text-fill-on-scroll','Text Fill on Scroll','Words light up one by one as you scroll. Best for key statements.'],- ['scroll-velocity-skew','Scroll Velocity Skew','Content shears with scroll speed and springs straight when you stop — motion mapped to velocity, not position.'],+ ['scroll-velocity-skew','Scroll Velocity Skew','Rows lean when you scroll fast and straighten when you stop. Best for galleries.'],['svg-line-draw','SVG Line Draw on Scroll','A winding route draws itself down the page via stroke-dashoffset, passing waypoints as you travel.'],['scrollspy-nav','Scrollspy Navigation','A nav rail tracks the section in view with a sliding indicator — the docs-site pattern.'],['scroll-background-color','Scroll-Driven Background Color','The background blends between section palettes as you scroll, flipping text contrast on light stops.'],