Skip to content

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.

fix: let Stagger Reveal's list and tags cascade where the visitor can see them

matina365462f3c46
diff --git a/animations/01-scroll-based/stagger-reveal/README.md b/animations/01-scroll-based/stagger-reveal/README.md
index 12a357a0..f38f81df 100644
--- a/animations/01-scroll-based/stagger-reveal/README.md
+++ b/animations/01-scroll-based/stagger-reveal/README.md
@@ -10,7 +10,7 @@ A stagger reveal shows a group of items one after another instead of all at once
- Any group where a uniform simultaneous appearance feels abrupt or mechanical
## How it works
-Each item shares one CSS transition (`opacity` and `translateY`) and starts hidden. An `IntersectionObserver` on each section triggers `staggerIn`, which computes an order array for the chosen direction and schedules each item's `.in` class with a delay of `orderIndex × staggerMs`:
+Each item shares one CSS transition (`opacity` and `translateY`) and starts hidden. An `IntersectionObserver` on each group (the grid, the list and the tags) triggers `staggerIn`, which computes an order array for the chosen direction and schedules each item's `.in` class with a delay of `orderIndex × staggerMs`:
```js
function getOrder(n) {
@@ -31,7 +31,7 @@ function staggerIn(items) {
The order array holds a *rank* per item, not a target — item `i` waits `order[i] × staggerMs`. Center-out works by using distance-from-center as the rank, so the middle items (rank 0) fire first.
-`later()` is `setTimeout` that also remembers its timer. A group plays once, when 5% of it is in the box. Back to top, pressing Play with the box already at its end, and changing a setting all call `rebuild()`, which cancels the timers still waiting, builds the three groups again hidden and attaches fresh observers, so the groups in the box play again with the current settings. The last group ends with 80px of padding, more than the 20px an item sits low before it appears; without it the hidden items would stretch the scroll length and give it back as they arrive, and a script that reads the length once (as the demo's Play button does) would aim at an end that is not there.
+`later()` is `setTimeout` that also remembers its timer. A group plays once, when half of it is in the box or its bottom edge has come into the box. The observers watch the group's items, not the section around them, so the cascade starts while the items are on screen instead of while they are still below the box; a threshold every 5% makes them report on the way, so a quick jump to the end is still noticed and no visible row is left hidden. Back to top, pressing Play with the box already at its end, and changing a setting all call `rebuild()` at once, which cancels the timers still waiting, builds the three groups again hidden and attaches fresh observers, so the groups in the box play again with the current settings. The observers report on the next frame, after the box has jumped to the top, so the finished groups are never drawn there. The last group ends with 80px of padding, more than the 20px an item sits low before it appears; without it the hidden items would stretch the scroll length and give it back as they arrive, and a script that reads the length once (as the demo's Play button does) would aim at an end that is not there.
## Key parameters
| Parameter | Default | Effect |
diff --git a/animations/01-scroll-based/stagger-reveal/index.html b/animations/01-scroll-based/stagger-reveal/index.html
index 61aa7f5e..9a0302d7 100644
--- a/animations/01-scroll-based/stagger-reveal/index.html
+++ b/animations/01-scroll-based/stagger-reveal/index.html
@@ -69,15 +69,15 @@
<div><h2 id="hb-watch-title">Scroll it</h2><p>Scroll inside the box, or press Play. Back to top hides the groups again.</p></div>
</div>
<div class="stage" id="stage" tabindex="0" role="region" aria-label="Three groups of items">
- <div class="section" id="sec-grid">
+ <div class="section">
<div class="sec-head">01 · Grid</div>
<div class="grid" id="grid"></div>
</div>
- <div class="section" id="sec-list">
+ <div class="section">
<div class="sec-head">02 · List</div>
<div id="list"></div>
</div>
- <div class="section" id="sec-chips">
+ <div class="section">
<div class="sec-head">03 · Tags</div>
<div class="chips" id="chips"></div>
</div>
@@ -155,7 +155,7 @@
<footer class="hb-foot"><span>Animation Handbook</span><a href="#top">Back to top ↑</a></footer>
<script>
const stage=document.getElementById('stage');
- let staggerMs=50,direction='forward',observers=[],timers=[],redo=0;
+ let staggerMs=50,direction='forward',observers=[],timers=[];
const GRID_ITEMS=['Alpha','Beta','Gamma','Delta','Epsilon','Zeta','Eta','Theta','Iota','Kappa','Lambda','Mu'];
const LIST_ITEMS=[
@@ -210,13 +210,17 @@
let gridItems=buildGrid(),listItems=buildList(),chipItems=buildChips();
- // Each group plays once, when 5% of it is in the box
+ // Each group plays once, when half of it is in the box or its bottom edge has come into the box. The observers watch the
+ // group's items, not the section around them, so the cascade starts while the items are on screen. A threshold every 5%
+ // makes them report on the way, so a jump straight to the end is not missed and no visible row is left hidden.
+ const STEPS=Array.from({length:21},(_,i)=>i/20);
function attachObservers(){
observers.forEach(o=>o.disconnect());observers=[];
- [['sec-grid',gridItems],['sec-list',listItems],['sec-chips',chipItems]].forEach(([id,items])=>{
+ [['grid',gridItems],['list',listItems],['chips',chipItems]].forEach(([id,items])=>{
const o=new IntersectionObserver(entries=>{
- if(entries[entries.length-1].isIntersecting){o.disconnect();staggerIn(items)}
- },{root:stage,threshold:.05});
+ const e=entries[entries.length-1];
+ if(e.isIntersecting&&(e.intersectionRatio>=.5||e.boundingClientRect.bottom<=e.rootBounds.bottom+1)){o.disconnect();staggerIn(items)}
+ },{root:stage,threshold:STEPS});
o.observe(document.getElementById(id));observers.push(o);
});
}
@@ -225,7 +229,6 @@
// Builds the three groups again, hidden, and watches them again: the groups in the box play at once with the current
// settings, the others when they scroll in
function rebuild(){
- clearTimeout(redo);
timers.forEach(clearTimeout);timers=[];
gridItems=buildGrid();listItems=buildList();chipItems=buildChips();
void stage.offsetWidth;
@@ -233,10 +236,11 @@
}
// Back to top, and Play pressed with the box at its end, hide the groups again. The shared script jumps the box to the top
- // when it handles the same click, after this listener, so the groups are rebuilt a moment later.
- document.getElementById('btn-top').addEventListener('click',()=>{clearTimeout(redo);redo=setTimeout(rebuild,50)});
+ // when it handles the same click, after this listener; the new observers report on the next frame, after the jump, so the
+ // finished groups are never drawn at the top.
+ document.getElementById('btn-top').addEventListener('click',()=>rebuild());
document.getElementById('btn-scroll').addEventListener('click',()=>{
- if(stage.scrollTop>=stage.scrollHeight-stage.clientHeight-2){clearTimeout(redo);redo=setTimeout(rebuild,50)}
+ if(stage.scrollTop>=stage.scrollHeight-stage.clientHeight-2)rebuild();
});
function choices(id,pick){
diff --git a/docs/superpowers/plans/2026-09-29-scroll-content-part1.md b/docs/superpowers/plans/2026-09-29-scroll-content-part1.md
index c1c35c1d..5b165907 100644
--- a/docs/superpowers/plans/2026-09-29-scroll-content-part1.md
+++ b/docs/superpowers/plans/2026-09-29-scroll-content-part1.md
@@ -950,10 +950,10 @@ None: leave out the `details.hb-options` block.
- **Step 1:** Scroll it · help line: "Scroll inside the box, or press Play. Back to top hides the groups again."
- **Player bar:** Play · Back to top
- **Scroller:** the stage.
-- **What scrolling shows:** three groups: a grid of twelve cards (two columns on phones), a list of six people and a cluster of eight tags. As each group comes into the box, its items fade in and rise one after another, a short delay apart, in the chosen order. A group stays shown after that. On a laptop the grid and the top of the list are in the box on arrival, so both play at once and the tags play as the box scrolls.
-- **Scroll distance and Play:** the groups' own height: about 1.3 box heights at 1280×800 (510px) and 2.7 on a phone (792px). Play reaches the tags about four seconds in (on phones and in the 258px box only the grid is in the box on arrival).
-- **Every group plays** (shared rule 4): a group has no line; it plays once 5% of it is in the box, and the box scrolls until the last group is wholly in view, so all three play at every size.
-- **Back to top, Play from the end, and settings:** Back to top, Play pressed with the box at its end, and every settings change rebuild the three groups hidden and watch them again, as today's Replay all groups did (without its scroll to the top). A new helper `rebuild()` clears the timers still pending from the last reveal, rebuilds the grid, list and chips hidden, and calls `attachObservers()`; the groups in the box then replay with the current settings. The page calls it on clicks on `#btn-top` and on `#btn-scroll` when `stage.scrollTop >= stage.scrollHeight - stage.clientHeight - 2`, 50ms later, after the jump to the top; a settings change calls it at once, so the difference shows where the box is. This relies on the order of the listeners: the page's inline script registers its click listeners before the shared script (loaded with `defer`) registers Play's and Back to top's, so on a click the page still sees the box at its end before Play jumps it to the top. The listeners must stay in the inline script's top level.
+- **What scrolling shows:** three groups: a grid of twelve cards (two columns on phones), a list of six people and a cluster of eight tags. As each group comes into the box, its items fade in and rise one after another, a short delay apart, in the chosen order. A group stays shown after that. On arrival the grid is in the box and plays at once; the list and the tags play as the box scrolls, each once half of it is in the box or its bottom edge is, so their cascades happen where the visitor can see them.
+- **Scroll distance and Play:** the groups' own height: about 1.3 box heights at 1280×800 (510px) and 2.7 on a phone (792px). Play reaches the list between about one and three seconds in (0.9 to 2.8 s: earlier in a tall box, later on a phone) and the tags about five seconds in (4.8 to 5.2 s), so their cascades end about when the six-second run does (only the grid plays on arrival, at every size).
+- **Every group plays** (shared rule 4): a group has no line. It plays once half of it is in the box, or its bottom edge has come into the box, so the last rows of a long group are never left hidden. The observers watch the group's items (`#grid`, `#list` and `#chips`), not the section around them (whose padding and heading made the cascade run before any item was on screen), and have a threshold every 5% (`Array.from({length:21},(_,i)=>i/20)`), so a jump straight to the end is not missed: a plain `threshold:.5` leaves the visible rows hidden at the end, and `[0,.5]` misses a jump from the top to the end. The box scrolls until the last group is wholly in view, so all three play at every size, and in Play 3 to 4 of the 6 list rows and all 8 tags are seen fading in at every size. Until a group plays, the items of it already in the box stay hidden (up to three list rows for about a second in Play).
+- **Back to top, Play from the end, and settings:** Back to top, Play pressed with the box at its end, and every settings change rebuild the three groups hidden and watch them again, as today's Replay all groups did (without its scroll to the top). A new helper `rebuild()` clears the timers still pending from the last reveal, rebuilds the grid, list and chips hidden, and calls `attachObservers()`; the groups in the box then replay with the current settings. The page calls it on clicks on `#btn-top`, and on `#btn-scroll` when `stage.scrollTop >= stage.scrollHeight - stage.clientHeight - 2`, at once in the same click, as a settings change does, so the difference shows where the box is. It does not wait for the jump to the top: the new observers first report on the next frame, after the shared script has jumped the box, so the groups in view play from the top and the finished groups are never drawn there (with a 50ms delay they stayed on screen for about four frames). This relies on the order of the listeners: the page's inline script registers its click listeners before the shared script (loaded with `defer`) registers Play's and Back to top's, so on a click the page still sees the box at its end before Play jumps it to the top. The listeners must stay in the inline script's top level.
- **Reduced motion:** nothing scrolls by itself. As today, the items appear in the same order and with the same delays, but without moving (`.item{transition:none!important}`).
- **Stage font:** site font.
- **Stage:**