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: let Snap Scrolling's dots sit inside the box so scrolling over them moves it
matin38b31762ddfd
diff --git a/animations/01-scroll-based/snap-scrolling/index.html b/animations/01-scroll-based/snap-scrolling/index.htmlindex b321864e..7300caaf 100644--- a/animations/01-scroll-based/snap-scrolling/index.html+++ b/animations/01-scroll-based/snap-scrolling/index.html@@ -40,7 +40,9 @@.stat-label{font-size:12px;color:var(--ui-muted);margin-top:3px}.pull-quote{font-size:clamp(16px,2.5vw,22px);line-height:1.5;max-width:420px;margin-bottom:12px}.quote-attr{font-size:11px;opacity:.5}- .snap-dots{position:absolute;right:4px;top:50%;transform:translateY(-50%);display:flex;flex-direction:column}+ /* The dots sit inside the scroller, in a zero-height sticky row: they stay in place while the sections move, and a swipe, a wheel turn or a key press that starts on them scrolls the box */+ .snap-rail{position:sticky;top:0;height:0;z-index:1}+ .snap-dots{position:absolute;right:4px;top:50cqh;transform:translateY(-50%);display:flex;flex-direction:column}.dot{width:44px;height:44px;padding:0;border:0;background:none;font:inherit;display:grid;place-items:center;cursor:pointer}.dot::before{content:'';width:8px;height:8px;border-radius:50%;background:var(--ui-muted);transition:background .2s,transform .2s}.dot.active::before{background:var(--ui-accent);transform:scale(1.4)}@@ -68,8 +70,7 @@<div><h2 id="hb-watch-title">Scroll it</h2><p>Scroll inside the box and let go: it settles on the nearest section. Press Play and it glides through without snapping.</p></div></div><div class="stage">- <div class="scroller" id="scroller" data-hb-scroller data-snap="mandatory" tabindex="0" role="region" aria-label="Five sections that the box snaps to"></div>- <div class="snap-dots" id="snap-dots"></div>+ <div class="scroller" id="scroller" data-hb-scroller data-snap="mandatory" tabindex="0" role="region" aria-label="Five sections that the box snaps to"><div class="snap-rail"><div class="snap-dots" id="snap-dots"></div></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>diff --git a/docs/superpowers/plans/2026-09-29-scroll-content-part1.md b/docs/superpowers/plans/2026-09-29-scroll-content-part1.mdindex c1c35c1d..71b71da6 100644--- a/docs/superpowers/plans/2026-09-29-scroll-content-part1.md+++ b/docs/superpowers/plans/2026-09-29-scroll-content-part1.md@@ -61,7 +61,7 @@ These decisions and the category rules below read the same in part 1 and part 2.- **Step 1** is titled "Scroll it". Its default help line is "Scroll inside the box, or press Play and it scrolls for you." A section gives a page-specific line where it helps.- **Player bar of a scroll page:** the Play button and then the Back to top button, exactly as in the do-it/scroll plan, and nothing else (no Slow motion, Replay, Loop or Pause).- **Try it help line of a scroll page:** "Change a setting, then scroll again or press Play.", the fixed line for the kind; no page has its own. Most settings here redraw the box at once, where it is; the section says when a change waits for the next scroll.-- **The scroller** is the `.stage` itself on eleven pages. On Snap Scrolling and Reveal on Scroll an overlay (the dots, the trigger line) sits beside the scroller so it does not scroll away: there the `.stage` does the job of today's `.stage-wrap` and holds an inner scroller marked `data-hb-scroller` plus the overlay, as on part 2's Progress Bar and Scrollspy Navigation. Its focus ring comes from the shared stylesheet (shared rule 2); the page adds nothing. Every scroller gets:+- **The scroller** is the `.stage` itself on eleven pages. On Snap Scrolling and Reveal on Scroll an overlay (the dots, the trigger line) has to stay in place while the content scrolls: there the `.stage` does the job of today's `.stage-wrap` and holds an inner scroller marked `data-hb-scroller`, as on part 2's Progress Bar and Scrollspy Navigation. An overlay the visitor can press (Snap Scrolling's dots) sits inside that scroller, in a zero-height sticky rail (`.snap-rail{position:sticky;top:0;height:0;z-index:1}` as the scroller's first child, the overlay absolutely placed in it with its `top` in `cqh`): beside the scroller it would be a dead strip where a swipe, a wheel turn, or a key pressed after a press, scrolled the page and not the box, and CLAUDE.md requires scroll-driven demos to work with touch scroll. An overlay that only shows something (Reveal on Scroll's trigger line) sits beside the scroller or over it with `pointer-events:none`, so input goes through to the box. Any other pressable overlay follows the rail rule (part 2's Scrollspy menu). The scroller's focus ring comes from the shared stylesheet (shared rule 2); the page adds nothing. Every scroller gets:- `tabindex="0" role="region"` and an `aria-label` (each section gives it), so keyboard users can focus it and scroll it with the arrow keys;- `overflow-y:auto` (was `scroll`), keeping today's hidden scrollbar (`scrollbar-width:none` and the `::-webkit-scrollbar{display:none}` rule);- `position:relative`, so the `offsetTop` of anything inside it is measured from its own top (Fly-in Fly-out Contact List and Pin Animation read `offsetTop` and have it today).@@ -724,7 +724,7 @@ None: leave out the `details.hb-options` block.- **Description:** The box settles on one whole section at a time. Best for slides and galleries.- **Step 1:** Scroll it · help line: "Scroll inside the box and let go: it settles on the nearest section. Press Play and it glides through without snapping." (owner decision 2)- **Player bar:** Play · Back to top-- **Scroller:** `<div class="scroller" id="scroller" data-hb-scroller tabindex="0" role="region" aria-label="Five sections that the box snaps to">` inside the `.stage`. The `.stage` does the job of today's `.stage-wrap`: it holds the dots beside the scroller, so they stay in place while the sections move. The script calls it `scroller` wherever it said `stage`.+- **Scroller:** `<div class="scroller" id="scroller" data-hb-scroller data-snap="mandatory" tabindex="0" role="region" aria-label="Five sections that the box snaps to"><div class="snap-rail"><div class="snap-dots" id="snap-dots"></div></div></div>` inside the `.stage`; the script appends the sections after the rail. The `.stage` does the job of today's `.stage-wrap`. The dots sit inside the scroller, in a zero-height sticky rail (category rule on the scroller), so they stay in place while the sections move and a swipe, a wheel turn or a key press that starts on them scrolls the box. Beside the scroller they were a 44×220px strip (13% of the width and 74% of the height of a 375px phone's box) where scrolling moved the page (found in review). The script calls it `scroller` wherever it said `stage`.- **What scrolling shows:** five full-box sections in different colours. Stop scrolling between two and the box glides to the nearer one, so a section always shows whole; with When close it only settles near a section, and with Off it stops anywhere. The dots at the right edge light up for the section in view, and pressing a dot glides to its section. Play glides straight through, because the shared script turns snapping off while it runs (shared rule 7); any input inside the stage stops Play (shared rule 6), snapping comes back, and the box settles on the nearest section by itself.- **Scroll distance and Play:** five sections at 100cqh: four box heights of scrolling (1,512px at 1280×800, 1,192px on a phone). Play glides through all five in six seconds, a section about every 1.5 seconds, without snapping (owner decision 2); the snapping shows when the visitor scrolls. The page does nothing for this: while Play runs, the shared script marks the scroller with `data-hb-autoscrolling` and a shared rule turns its snapping off; when the run ends or is stopped, the page's own snapping applies again, including a Snapping choice made during the run (shared rule 7).- **Reduced motion:** nothing scrolls by itself. As today, the box lands on a section at once instead of gliding, and the dots change without their transition: the demo's rule becomes `@media(prefers-reduced-motion:reduce){.scroller{scroll-behavior:auto!important}.dot::before{transition:none!important}}`.@@ -734,7 +734,7 @@ None: leave out the `details.hb-options` block.- `.scroller`: `height:100%;overflow-y:auto;scrollbar-width:none;position:relative;container-type:size;scroll-behavior:smooth`, with the `::-webkit-scrollbar{display:none}` rule. The old stage's border and height go.- Snapping comes from an attribute (shared rule 7): the scroller starts with `data-snap="mandatory"`, and three rules read it: `.scroller[data-snap="mandatory"]{scroll-snap-type:y mandatory}`, `.scroller[data-snap="proximity"]{scroll-snap-type:y proximity}` and `.scroller[data-snap="off"]{scroll-snap-type:none}`. None uses `!important`, so the shared rule can turn snapping off during Play.- `.section{height:100cqh}` (was 620px, 480px on phones). The script's `620` becomes `scroller.clientHeight` (the dot and the section in view: `Math.min(Math.round(scroller.scrollTop / scroller.clientHeight), 4)`; the dot's jump: `scroller.scrollTo({ top: i * scroller.clientHeight })`, without `behavior`, so the box's own `scroll-behavior` decides: a glide, or a jump under reduced motion).- - The dots sit at the right edge inside the box on every screen: `.snap-dots{position:absolute;right:4px;top:50%;transform:translateY(-50%);display:flex;flex-direction:column}`; the phone rule that fixed them to the window goes. Each dot becomes `<button type="button" class="dot" aria-label="Section 1">` (to 5): `.dot{width:44px;height:44px;padding:0;border:0;background:none;display:grid;place-items:center;cursor:pointer}`, with the 8px dot drawn by `.dot::before{content:'';width:8px;height:8px;border-radius:50%;background:var(--ui-muted);transition:background .2s,transform .2s}` and `.dot.active::before{background:var(--ui-accent);transform:scale(1.4)}`. The active dot also gets `aria-current="true"`. The shared script stops Play on any press inside the stage, so a dot works during Play too. Five dots take 220px, which fits the 258px box of a 1280×590 window and the 298px phone box. The dots' focus ring comes from the shared stylesheet (shared rule 2).+ - The dots sit at the right edge inside the box on every screen, in the rail: `.snap-rail{position:sticky;top:0;height:0;z-index:1}` (the scroller's first child, so it sticks to the top of the box while the sections scroll under it, and adds nothing to the scroll range, the section offsets or the first snap point at 0) and `.snap-dots{position:absolute;right:4px;top:50cqh;transform:translateY(-50%);display:flex;flex-direction:column}` (`50cqh` is half the scroller's height; a percentage would be of the 0px-tall rail); the phone rule that fixed them to the window goes. Each dot becomes `<button type="button" class="dot" aria-label="Section 1">` (to 5): `.dot{width:44px;height:44px;padding:0;border:0;background:none;font:inherit;display:grid;place-items:center;cursor:pointer}` (`font:inherit`: a button computes Arial otherwise, and the stage's font audit then finds only the site font), with the 8px dot drawn by `.dot::before{content:'';width:8px;height:8px;border-radius:50%;background:var(--ui-muted);transition:background .2s,transform .2s}` and `.dot.active::before{background:var(--ui-accent);transform:scale(1.4)}`. The active dot also gets `aria-current="true"`. The shared script stops Play on any press inside the stage, so a dot works during Play too. Five dots take 220px, which fits the 258px box of a 1280×590 window and the 298px phone box. The dots' focus ring comes from the shared stylesheet (shared rule 2).- The section texts are rewritten in plain words (today's speak of the browser engine, CSS and JavaScript):| Section | Title | Text |@@ -768,6 +768,7 @@ None: leave out the `details.hb-options` block.> Add snap scrolling to [your page of full-height sections, slides or gallery]. Make each section exactly as tall as the scrolling area and mark its top as a snap point, so that, as the settings choose, the view settles on the nearest section instead of stopping between two. Use the browser's built-in scroll snapping rather than a script. Add small dots that show which section is in view and take the visitor to a section when pressed. Check scrolling with the arrow keys too, because strict snapping can feel stiff there. If the visitor has reduced motion turned on, let the view settle without a smooth glide. Match the settings listed below.+- **Copy prompt hint:** the template line, "Replace the words in brackets with your own element. Your settings are added at the end." (this section gave none; every other scroll page with settings uses the template line)- **README What it is:** rewritten:> Snap scrolling makes a scrolling area settle on set points instead of stopping anywhere. When you stop scrolling, the browser pulls the view to the nearest section, so each section is shown whole, like turning pages. The browser does the pulling on its own; no script is needed for it.