Counter Scroll
Four number cards in a two-column grid: each one fades up as it enters its area, then, once it is half visible, its number counts from 0 to its target in 2 seconds — 150 ms later for each card down the order. One intersection observer per area, 40 lines of JavaScript, no dependency.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Scroll has 74 effects, including 12 free. Explore the category →
3 usage examples



How it works
The cards arrive in CSS. Each .sb-counter-card starts at opacity: 0; translateY(30px) and replays fx0544FadeUp on animation-timeline: view(), range entry entry 50%. In the demo (280 px area, 86 px cards set under 300 px of top padding) the box is empty on opening; the first row starts to show around 20 px scrolled, sits at 0.46 opacity at 40 px, 0.69 at 50 and 1 at 70.
The counting is JavaScript. For each .sb-counter-scroll area, an IntersectionObserver whose root is the area itself watches the cards at threshold 0.5. Readings: the first row fires between 70 and 74 px scrolled, the second around 170. The card then gets data-counted="1" and its span.sb-counter starts after index × 150 ms (0, 150, 300, 450 ms for the four cards). The number shown is Math.floor(target × elapsed time / 2000): linear progress, 75 out of 150 after one second, exact value at the end (last write measured at 2,017 ms).
Three details matter in use. The target is read from data-target by parseInt: integers only (12.7 stops at 12), no thousands separator (1,250,000 is written 1250000). The suffix (+, %, /7, K) lives in a separate, smaller span.sb-counter-suffix the script never touches. And the count plays once: scrolling up then down again leaves the final values in place. Duration is measured on the clock, not in frames: it is the same on a 60 Hz or a 120 Hz screen.
Accessibility
- Without JavaScript the cards show 0: the real value only exists in the
data-targetattribute. If these figures are information, state them twice — for instancearia-label="more than 150 projects"withrole="img"on.sb-counter-number, or a plain sentence under the grid. - Screen readers: the
span's text changes on every frame for two seconds, with noaria-liveregion — just as well, nothing is announced in a burst. In return, a card read before its count says “0”, and the suffix, in its ownspan, may be read as a separate word. The label suggested above fixes both. - Reduced motion: with
prefers-reduced-motion: reduce, the script writes every final value on load and counts nothing, and the CSS drops the 30 px rise: an entering card only brightens, where it sits, at the pace of the scroll (measured: first row at 1 after 120 px, with no offset). The hint stops blinking. To show everything at once, replaceanimation-namein that block withanimation: none; opacity: 1. - Contrast and keyboard: the digits are a gradient from
#6366f1(4.1:1 on the card background) to#d946ef(5.3:1), 29 px bold; the labels at 50% white, 11 px capitals, reach 5.3:1. The area carriestabindex="0",role="region"and anaria-label: it takes focus on Tab in Chromium 149, Firefox 151 and WebKit 26.5, which skipped it without the attribute; a 2 px violet outline, drawn inside, then shows where you are.
Browser compatibility
The counting relies on IntersectionObserver (Chrome 51, Firefox 55, Safari 12.1) and requestAnimationFrame: it works wherever the site works. Only the fade-in depends on animation-timeline: view() (Chrome and Edge 115, Safari 26, Firefox 159 per MDN). Trials: Chromium 149, WebKit 26.5 and Firefox 151, two areas on the same page, each with its own counters.
Without animation-timeline: the cards are visible straight away (the hidden state sits in an @supports) and still count. Without IntersectionObserver: every counter starts on load. Without JavaScript: zeros.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0544-root">
<div class="sdc-scroll-container sb-counter-scroll" tabindex="0" role="region" aria-label="…">
<div class="sb-counter-content">
<div class="sb-counter-card">
<div class="sb-counter-number">
<span class="sb-counter" data-target="150">0</span>
<span class="sb-counter-suffix">+</span>
</div>
<div class="sb-counter-label">…</div>
</div>
… ×4
</div>
</div>
<span class="sdc-scroll-hint" aria-hidden="true">…</span>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Target value (HTML — data-target on span.sb-counter) |
150, 98, 24, 500 | An integer. Decimals are cut off, no thousands separator is added: above 9,999, prefer “12” with a “k” suffix. |
Suffix (HTML — span.sb-counter-suffix) |
+, %, /7, K | Free text, shown smaller (1.2rem against 1.8rem) in the same gradient. Delete the span for a bare number. |
Count duration (JS — var duration = 2000) |
2,000 ms | 1,000 ms for small numbers (counting to 3 in two seconds feels slow); beyond 3,000 ms the reader has often finished reading before the number lands. |
Stagger between cards (JS — i * 150) |
150 ms per position | The position is the card's index in its area: with twelve cards the last one waits 1.65 s. Use 0 for a grouped start, or (i % 2) * 150 to delay the right-hand column only. |
Trigger threshold (JS — threshold: 0.5) |
card half visible | At 0.5 the counter starts as the fade ends. 1 waits for the whole card; 0 starts at the first pixel, while the card is still transparent. |
What triggers: the area or the page (JS — root: container) |
the .sb-counter-scroll area |
In a page that scrolls with no inner box, remove height and overflow-y from the area and replace root: container with root: null: the cards count as they reach the window (tried). Without that change everything would count on load. |
Grid (CSS — .sb-counter-content { grid-template-columns: repeat(2, 1fr); padding: 300px 12px 40px }) |
2 columns, under 300 px of top padding | repeat(4, 1fr) lines the four cards up. The top 300 px only serve the demo, so the cards come in from the bottom of the area: under your own content, bring them down to 40 px. The tray has no fixed height; the travel ends 40 px below the last row. |
FAQ
.sb-counter-scroll area, because visibility is judged against it. They stay at 0 if the class is missing, if the block is not inside a .fx-0544-root root, or as long as the card is not half inside the area. They all start on opening if the area no longer has a fixed height: it then wraps all its cards, which are “visible” to it even off screen. Switch the observation root to null (see the settings).data-counted and is not restarted. To replay, remove that attribute and set the text back to 0 when the card leaves the area: in the observer's callback, that is the case where entry.isIntersecting is false, ignored today. Keep it for pages people rarely scroll back through: a figure that recounts at every flick of the wheel wears thin quickly.