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: never leave Counter Animation's numbers stuck at zero
matina0599d612c55
diff --git a/animations/01-scroll-based/counter-animation/README.md b/animations/01-scroll-based/counter-animation/README.mdindex c74ae82f..f0d0340b 100644--- a/animations/01-scroll-based/counter-animation/README.md+++ b/animations/01-scroll-based/counter-animation/README.md@@ -45,7 +45,7 @@ Every count starts from zero. The observer decides when the numbers may start; eThe revenue number changes format as it grows, from dollars to thousands to millions, so its widest string is never wider than the final "12,847" and always fits its tile on a phone.-A second observer, shrunk by a few pixels at the bottom, watches for the stats container leaving the box altogether; it stops any count in progress and puts the numbers back to zero, so after Back to top or Play at the end they scroll in at zero again instead of showing the old totals first.+A second observer, shrunk by 8px at the bottom, watches for the stats container leaving the box altogether; it stops any count in progress and puts the numbers back to zero, so after Back to top or Play at the end they scroll in at zero again instead of showing the old totals first. Its margin is smaller than any of the lines a count starts at, so the counting observer has always let go first and a count can start again on the way down.The four Feel choices use these curves: Even is `linear`, Smooth is `outCubic`, Slow finish is `outExpo` and Springy is `outBack`:@@ -62,7 +62,7 @@ const EASE = {| Parameter | Default | Effect ||-----------|---------|--------|-| Starts counting | Middle | Where the top of the numbers must reach before they count: early is a tenth of the way up the box, middle 40% of the way up and late 70% |+| Starts counting | Middle | The line the top of the tiles must pass before the numbers may count: early is a tenth of the way up the box, middle 40% of the way up and late 70%. Each number then waits until half of it is inside the box, so on a short box early and middle start at almost the same place || Speed | Normal | How long each count takes: slow is 2.9 s, normal 1.8 s and fast 1.1 s || Feel | Smooth | Smooth slows to a stop; Slow finish races to near the total, then creeps through the last digits; Springy goes a little past and settles back; Even counts at one steady pace, which feels mechanical || One after another | on | Each number starts 200ms after the one before, so the four count in a cascade |diff --git a/animations/01-scroll-based/counter-animation/index.html b/animations/01-scroll-based/counter-animation/index.htmlindex bad50792..8bc89b15 100644--- a/animations/01-scroll-based/counter-animation/index.html+++ b/animations/01-scroll-based/counter-animation/index.html@@ -217,12 +217,13 @@observer.observe(stats);}- // Once the tiles are out of the box (their top less than 32px inside it; the first number starts about 70px lower), the- // numbers go back to zero. After Back to top, or Play at the end, they scroll in at zero again instead of showing the- // old totals first.+ // Once the tiles are out of the box (their top less than 8px inside it, when no number shows yet), the numbers go back to+ // zero. After Back to top, or Play at the end, they scroll in at zero again instead of showing the old totals first. The+ // margin stays well under the smallest "Starts counting" line (a tenth of the box, about 25px at 258px), so the counting+ // observer has always let go before this one resets, and a count can start again on the way down.new IntersectionObserver(entries=>{if(!entries[entries.length-1].isIntersecting)resetCounters();- },{root:stage,rootMargin:'0px 0px -32px 0px',threshold:0}).observe(stats);+ },{root:stage,rootMargin:'0px 0px -8px 0px',threshold:0}).observe(stats);function choices(id,pick){const buttons=document.querySelectorAll('#'+id+' button');diff --git a/docs/superpowers/plans/2026-09-29-scroll-content-part2.md b/docs/superpowers/plans/2026-09-29-scroll-content-part2.mdindex 80a57fe4..51793e3b 100644--- a/docs/superpowers/plans/2026-09-29-scroll-content-part2.md+++ b/docs/superpowers/plans/2026-09-29-scroll-content-part2.md@@ -251,9 +251,9 @@ The two lists below, A and B, were settled after both halves were reviewed. They- **Step 1:** Scroll it · help line: default- **Player bar:** Play · Back to top- **Scroller:** the stage.-- **What scrolling shows:** the cue "Scroll down ↓", then four tiles (active users, uptime, revenue, experience). When the top of the tiles passes the line that Starts counting sets, the four numbers count up from zero to 12,847, 98.4%, $2.4M and 8 yrs, formatted the whole way. Scrolling back above the line and down again counts again; as today, the numbers keep their totals until the next count starts from zero.-- **Scroll distance and Play:** a 100cqh lead-in, then `#stats`, which holds the tiles. Measured, the tiles need 292px on phones, 345px at 768×1024 and 402px on laptops; at 768×1024 the 80cqh minimum below (350px) is the taller. The empty spacer after the tiles goes, so the box ends with the tiles in view instead of an empty screen. `#stats` gets `min-height:80cqh`, so the box always scrolls at least 80cqh. Late needs 70cqh, so every Starts counting choice is reached at every size (rule B4). Measured on a prototype at 610×1000, 640×1000, 768×1024, 1280×590, 1366×657, 1280×800, 375×812 and 320×640: all three lines are reached at each. At the default (Middle), Play reaches the line 1.6 s into its pass at 1280×590, 2.0 s at 1366×657, 2.5 s on phones and 3.0 s on tablets. The count (1.8 s, with 0.6 s more for the last tile) ends before the box stops: at 5.4 s at the latest, on a 768×1024 tablet.-- **Reduced motion:** nothing scrolls by itself. As today, the numbers jump to their totals when the tiles pass the line (the `motionOk` branch stays). The CSS rule `.tile-num{transition:none}` goes: the numbers have no transition.+- **What scrolling shows:** the cue "Scroll down ↓", then four tiles (active users, uptime, revenue, experience). When the top of the tiles passes the line that Starts counting sets, the four numbers may count up from zero to 12,847, 98.4%, $2.4M and 8 yrs, formatted the whole way. Each number starts once the one before it has (200 ms later with One after another on) and once half of it is inside the box, so the lower row, still below the box when the tiles pass the line, is seen counting when it scrolls in (started by the line alone, revenue and experience were already 50–100% counted, at most sizes 88–100%, when they were half in view). All four show zero together when a count starts. Scrolling back above the line and down again counts again, and the numbers keep their totals until then. Once the tiles are out of the box altogether (their top less than 8px inside it, when no number shows yet), the numbers go back to zero, so after Back to top, Play at the end or the Home key they scroll in at zero and never show the old totals first. The revenue reads $9,999 and below, then $10K to $999K, then $1.0M to $2.4M, so no string is wider than "12,847".+- **Scroll distance and Play:** a 100cqh lead-in, then `#stats`, which holds the tiles. Measured, the tiles need 292px on phones, 345px at 768×1024 and 402px on laptops; at 768×1024 the 80cqh minimum below (350px) is the taller. The empty spacer after the tiles goes, so the box ends with the tiles in view instead of an empty screen. `#stats` gets `min-height:80cqh`, so the box always scrolls at least 80cqh. Late needs 70cqh, so every Starts counting choice is reached at every size (rule B4). Measured on a prototype at 610×1000, 640×1000, 768×1024, 1280×590, 1366×657, 1280×800, 375×812 and 320×640: all three lines are reached at each. At the default (Middle), Play reaches the line 1.6 s into its pass at 1280×590, 2.0 s at 1366×657, 2.5 s on phones and 3.0 s on tablets. The upper two numbers have finished by 3.9–5.3 s; the lower two start when they come into the box, at about 4.4–5.0 s, so at the defaults the last number finishes 0.4–0.6 s after the box stops at about 6.4 s (measured 0.40–0.58 s at 1280×590, 1366×657, 1280×800, 768×1024, 375×812 and 320×640), and about 1.7 s after it with Late on a tablet (768×1024). The numbers are then at rest in view.+- **Reduced motion:** nothing scrolls by itself. As today, the numbers jump to their totals when the tiles pass the line (the `motionOk` branch stays), all four at the same moment: no cascade, and no waiting for the lower row to come into the box. The CSS rule `.tile-num{transition:none}` goes: the numbers have no transition.- **Stage font:** site font. `.tile-num` drops `var(--disp)` and keeps weight 700.- **Stage:**- `.stage`: `position:relative;overflow-y:auto;scrollbar-width:none;container-type:size;background:#0b0b0d`, with `aria-label="Numbers that count up as they scroll into view"`.@@ -261,6 +261,9 @@ The two lists below, A and B, were settled after both halves were reviewed. They- `#stats` keeps its grid, gap and padding and adds `min-height:80cqh;align-content:start`, so the tiles stay packed at the top of that space.- `.tile-label` becomes 12px `#8a8a92` (was 10px at opacity .5). Each `.tile-icon` gets `aria-hidden="true"`.- Each `.tile-num` gets `role="img"` and an `aria-label` with its total as shown at the end ("12,847", "98.4%", "$2.4M", "8 yrs"), because its text changes every frame.+ - `.tile` gets `container-type:inline-size`, and `.tile-num` gets `font-size:min(clamp(28px,4.5vw,44px),26cqw)` (was `clamp(28px,4.5vw,44px)`) and `white-space:nowrap`. The site font's tabular figures make every digit, comma, period and % 0.635em wide, so "12,847" is 107px at 28px and did not fit a phone tile narrower than that (its content box is 84px at 320px and 104px at 360px). The number is 27px at 360px, 21.8px at 320px and unchanged from 375px up. Measured over every value each number shows, up to 112% of its total (Springy's overshoot), at 18 sizes from 1280×590 to 320×640, two of them landscape phones: no string is wider than its tile's content box (tightest 0.8px, at 320px).+ - The revenue reads `$9,999` and below, `$10K` to `$999K` (`Math.floor(v / 1e3)`), then `$1.0M` to `$2.4M`, instead of `$999,999` below a million: that string is 5em wide and stuck out of its tile's border by 4–14px on phones up to 390px wide, for about 0.3 s (about 1.2 s with Even and Slow). The final "$2.4M" and the aria-label are unchanged. Numbers are formatted with `toLocaleString('en-US')`, so the commas always match the aria-labels.+ - Script: the counting observer is as before (it reads the last entry). Each number starts once the number before it has begun (plus 200 ms with the cascade on) and once its middle is above the box's bottom edge, checked on every frame; all four are set to zero when a count starts, and speed, feel and cascade are read then. A second observer on `#stats`, with `rootMargin:'0px 0px -8px 0px'`, stops a count in progress and puts the numbers back to zero once the tiles are out of the box. The margin must not be 0, because at scrollTop 0 the tiles touch the box's bottom edge and still count as intersecting. It must stay under the smallest Early line (a tenth of the box: about 25px at 258px): 32px was built first, and it reset the numbers while the counting observer still saw the tiles past its line, so with Early on a box under 320px tall they stayed at zero after the visitor scrolled back up and stopped between the two (found at review, fixed). Reduced motion is read when a count starts.- Phone rules: none. Today's mobile block repeated the two-column grid.- `hb-dots`: no. Default height.@@ -268,7 +271,7 @@ The two lists below, A and B, were settled after both halves were reviewed. They| Setting | Control | Choices or range (value shown) | Default | Hint | Sets in the demo ||---|---|---|---|---|---|-| Starts counting | Choice buttons | Early · Middle · Late | Middle | How far the numbers scroll into the box before counting. | `threshold`: 90 / 60 / 30, then `buildObserver()` (its bottom `rootMargin` is −10% / −40% / −70%) |+| Starts counting | Choice buttons | Early · Middle · Late | Middle | How far the numbers scroll into the box before counting. | `threshold`: 90 / 60 / 30, then `buildObserver()` (its bottom `rootMargin` is −10% / −40% / −70%); a number also waits until half of it is inside the box || Speed | Choice buttons | Slow · Normal · Fast | Normal | How long the numbers take to reach their totals. | `duration`: 2900 / 1800 / 1100 (ms), used from the next count || Feel | Choice buttons | Smooth · Slow finish · Springy · Even | Smooth | Springy goes a little past each total, then settles. | `easing`: `'outCubic'` / `'outExpo'` / `'outBack'` / `'linear'`, used from the next count |@@ -276,8 +279,12 @@ The two lists below, A and B, were settled after both halves were reviewed. They| Setting | Control | Choices or range (value shown) | Default | Hint | Sets in the demo ||---|---|---|---|---|---|-| One after another | Switch | on / off | on | Each number starts a moment after the one before. | `staggerTog.checked`: the delays are `i × 200` ms / all 0, used from the next count |+| One after another | Switch | on / off | on | Each number starts a moment after the one before. | `staggerTog.checked`: each number starts 200 ms after the one before / all together (each still waits until half of it is inside the box), used from the next count |+- **Known limits (accepted at the Task 9 review, 2026-09-30):**+ - Early and Middle start close together on short boxes: a number cannot start before half of it is inside the box, and the first number is about 70–96px below the tiles' top. Scroll position where the first number and the lower row start, for Early · Middle · Late (measured, Play from the top): 1280×590 121/297 · 121/297 · 182/297 (Early and Middle at the same place); 1366×657 121/297 · 132/297 · 229/297; 1280×800 121/297 · 153/297 · 266/297; 768×1024 101/258 · 177/258 · 308/332; 601×700 88/225 · 148/225 · 258/278; 375×812 86/221 · 121/221 · 209/230. At laptop sizes the lower row starts at the same place whichever choice is picked.+ - The end timing (see Scroll distance and Play): the last number settles in view, after the box has stopped.+ - An End-key jump (or a very fast wheel) at 1280×590 lets the upper two numbers finish counting just above the box: the wait looks at the bottom edge only, so a number already above the box when its turn comes counts unseen (after End they change 102 and 94 times while wholly above it, and end 46px above its top edge). At 1366×657, 1280×800, 768×1024, 375×812 and 812×375 they stay at least partly in view. Play and paced scrolling show every number.- **Removed:**- The note, and the Live values readouts (they repeated the numbers).- Replay counters. Scrolling back above the line and down again counts again, and so do Back to top and Play.@@ -298,7 +305,7 @@ The two lists below, A and B, were settled after both halves were reviewed. They| Parameter | Default | Effect ||-----------|---------|--------|- | Starts counting | Middle | Where the top of the numbers must reach before they count: early is a tenth of the way up the box, middle 40% of the way up and late 70% |+ | Starts counting | Middle | The line the top of the tiles must pass before the numbers may count: early is a tenth of the way up the box, middle 40% of the way up and late 70%. Each number then waits until half of it is inside the box, so on a short box early and middle start at almost the same place || Speed | Normal | How long each count takes: slow is 2.9 s, normal 1.8 s and fast 1.1 s || Feel | Smooth | Smooth slows to a stop; Slow finish races to near the total, then creeps through the last digits; Springy goes a little past and settles back; Even counts at one steady pace, which feels mechanical || One after another | on | Each number starts 200ms after the one before, so the four count in a cascade |@@ -306,7 +313,7 @@ The two lists below, A and B, were settled after both halves were reviewed. They- **README See also:**- [Reveal on Scroll](../reveal-on-scroll/) — cards appear as they scroll into view- [Stagger Reveal](../stagger-reveal/) — items appear one after another as their group scrolls in-- **README How it works:** the text and snippets stay. The "Easing functions available:" sentence and its snippet move from Key parameters to the end of How it works, because the Key parameters section may hold no code. The sentence becomes "The four Feel choices use these curves: Even is `linear`, Smooth is `outCubic`, Slow finish is `outExpo` and Springy is `outBack`:".+- **README How it works:** the text and snippets stay, with these changes so that it matches the code. The observer snippet reads `entries[entries.length - 1]` instead of `[e]`, and the frame snippet uses `begun` (when a number's own count started) instead of `start` and `delay`. After the paragraph that ends "not suddenly at the final value." come three paragraphs: every count starts from zero, each number starts once the one before it has and half of it is inside the box, speed, curve and cascade are read when a count starts, and reduced motion jumps straight to the totals; the revenue changes format as it grows; and a second observer, shrunk by 8px at the bottom, puts the numbers back to zero when the tiles leave the box (its margin is smaller than any counting line, so a count can start again on the way down). The "Easing functions available:" sentence and its snippet move from Key parameters to the end of How it works, because the Key parameters section may hold no code. The sentence becomes "The four Feel choices use these curves: Even is `linear`, Smooth is `outCubic`, Slow finish is `outExpo` and Springy is `outBack`:".- **README Production notes:** unchanged- **Category line:** `01.16 · Scroll-Based`- **Pager:** Previous: Sticky Section (`../sticky-section/`) · Next: Progress Bar (`../progress-bar/`)