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
fix: keep Scroll Velocity Skew's rows straight when the window resizes
matin9e28d73702f7
diff --git a/animations/01-scroll-based/scroll-velocity-skew/README.md b/animations/01-scroll-based/scroll-velocity-skew/README.mdindex d2856aba..57bdee8d 100644--- a/animations/01-scroll-based/scroll-velocity-skew/README.md+++ b/animations/01-scroll-based/scroll-velocity-skew/README.md@@ -28,7 +28,7 @@ function tick(now) {}```-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.+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, and so can a window resize (the browser keeps the list inside its new range); when either button is clicked or the window is resized, 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 parametersdiff --git a/animations/01-scroll-based/scroll-velocity-skew/index.html b/animations/01-scroll-based/scroll-velocity-skew/index.htmlindex f34ce243..fd533320 100644--- a/animations/01-scroll-based/scroll-velocity-skew/index.html+++ b/animations/01-scroll-based/scroll-velocity-skew/index.html@@ -202,6 +202,8 @@// 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});+ // A resize can move the box too (the browser keeps the list inside its new, shorter range): that is not speed either.+ window.addEventListener('resize',()=>{lastTop=seenTop=stage.scrollTop});function setAxis(a){axis=a;diff --git a/docs/superpowers/plans/2026-09-29-scroll-content-part2.md b/docs/superpowers/plans/2026-09-29-scroll-content-part2.mdindex babf5c99..2298df30 100644--- a/docs/superpowers/plans/2026-09-29-scroll-content-part2.md+++ b/docs/superpowers/plans/2026-09-29-scroll-content-part2.md@@ -826,7 +826,9 @@ None: leave out the `details.hb-options` block.- The "scroll to shear" line on every row (`.m-tag`) goes.- Script: `tick()` and `applySkew()` stay; the readout lines, `measure()` and `maxScroll` go (they only fed the Position readout). Two changes follow rule B8:- **Speed per 1/60 s.** `tick(now)` works out `dt`, the time since the previous frame, kept between 1ms and 50ms: `dt=lastTime?Math.min(Math.max(now-lastTime,1),50):FRAME`, with `FRAME=1000/60`. It uses `raw=(top-lastTop)*FRAME/dt`, and the smoothing step uses the same time: `vel+=(raw-vel)*(1-Math.pow(1-SMOOTH,dt/FRAME))`. So a 120Hz screen leans and springs back as a 60Hz one does. Where the `scroll` listener starts the loop, it also sets `lastTime=0`, so the first frame of a run counts as 1/60 s. A frame's timestamp can be earlier than the moment the loop started, so a measured first `dt` would inflate the speed.- - **Instant jumps are ignored.** Back to top, and Play restarting from the top, move the box in one frame, which today leans the rows to the full limit for a moment. The page listens for `click` on `#btn-top` and `#btn-scroll` (by id) and sets `jumped=true`. The next `tick()` then sets `lastTop` to the current position before measuring, so that frame adds no speed.+ - **Instant jumps are ignored.** Back to top, and Play restarting from the top, move the box in one frame, which today leans the rows to the full limit for a moment. The shared script moves the box while it handles the click, before the click reaches the document, so a `click` listener on the document (for `#btn-top` and `#btn-scroll`, matched by id) sets `lastTop=seenTop=stage.scrollTop`: the jump adds no speed, and no flag is left behind that could swallow a later move. Built as the review of Task 13 accepted it, replacing the `jumped` flag that `tick()` would read. A `resize` listener does the same, because a resize can move the box too (1280×800 to 768×1024 while resting at the end leaned the rows to -12° for a second).+ - **A run starts from where the box was before its first move.** `seenTop` is where the last `scroll` event left the box. When the listener starts a run it sets `lastTop=seenTop` (the original set it to the position after the move), so a single instant notch of the wheel counts as speed (5.04° at Normal; 0° with the original start, in a browser with smooth scrolling off).+ - `.content` gets `overflow:clip`: a leaning row draws outside its box, which made the scrollable area up to 131px taller while the rows leaned and shorter again afterwards. Clipping at the padding box changes no picture (the clip edges are the edges of the scrolling content) and keeps the range constant.- Phone rules: none. Today's mobile block held only the stage size and the aside.- `hb-dots`: no. Default height.@@ -889,7 +891,7 @@ None: leave out the `details.hb-options` block.}```- - At the end of the paragraph after it, add: "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; the demo skips the frame after a click on either button, so that jump does not count as speed."+ - At the end of the paragraph after it, add: "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, and so can a window resize (the browser keeps the list inside its new range); when either button is clicked or the window is resized, 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."- The rest is unchanged.- **README Production notes:** unchanged- **Category line:** `01.23 · Scroll-Based`