ScrollPremium

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.

JSCounterScroll

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

Removal estimate — volume, boxes, hours and movers counted after clicking “Estimate” — Counter Scroll example 1

① Removal estimate — volume, boxes, hours and movers counted after clicking “Estimate”

WhenA form on the left, a result area on the right, empty until something is asked. On clicking “Estimate” the area slides to the result: four figures rise and start counting, then the price shows below.
WhyThe count gives the feeling of a calculation being done, and the 150 ms stagger makes the figures read in order: volume, boxes, duration, crew.
SettingsLight theme, 34 px digits in a blue-green gradient, targets 32, 45, 6 and 3, suffixes “m³” and “h”. A 324 px waiting block fills the area at the start, the cards sit below it; the button slides the area through a script in the scene. In the capture, the click is sent by that script.
“Your year of reading” — annual recap in a library network's app — Counter Scroll example 2

② “Your year of reading” — annual recap in a library network's app

WhenA summary screen swiped with the thumb: a title, then four tiles — books borrowed, pages read, genres, favourites — that arrive and count in turn, and a share button.
WhyIt is a reward: watching the number climb to your own score lands better than a figure simply placed there. Each tile counts when it arrives, not before: nothing plays off screen.
SettingsColours from the code (indigo → magenta gradient), 36 px digits, targets 47, 12 (suffix “k”), 9 and 5; 326 px area in a phone frame, a 326 px title above the tiles. Capture scrolling driven by script.
Counters of a bike swap day — sports-hall screen at the end of the day — Counter Scroll example 3

③ Counters of a bike swap day — sports-hall screen at the end of the day

WhenOn a large screen the day's poster gives way to the results: bikes dropped off, sold, share that found a new owner, repairs on site. The four numbers count in very large type.
WhyFrom a distance, a running number draws the eye to the board; once stopped it stays readable ten metres away. The separate “%” suffix stays small next to a 56 px digit.
Settings56 px digits, lime → yellow gradient, targets 214, 187, 87 (suffix “%”) and 23; 360 px area, a 360 px poster above. The switch from poster to results is done by a script in the scene; the effect only counts once per page view.

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-target attribute. If these figures are information, state them twice — for instance aria-label="more than 150 projects" with role="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 no aria-live region — just as well, nothing is announced in a burst. In return, a card read before its count says “0”, and the suffix, in its own span, 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, replace animation-name in that block with animation: 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 carries tabindex="0", role="region" and an aria-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.

Chrome 115+✓ Full (measured, Chromium 149)
Edge 115+✓ Full according to the tables, not verified
Safari 26+✓ Full in the WebKit 26.5 test build; real Safari not verified
Firefox 55 to 158✓ Full counting, cards placed without fade (measured, Firefox 151)
Firefox 159+✓ Fade included according to the tables — not verified
Safari 12.1 to 25✓ Counting without fade — not verified

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):

index.html — structure
<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 / propertyDefaultEffect
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

Number Counter Scroll watches the whole grid: when 30% of the block is visible, all the numbers start together, and the suffix is appended by the script inside the same element. Here each card is watched on its own, starts when it is half in, 150 ms after its neighbour, and its fade-in is tied to scrolling in CSS. On a long list of figures this version only plays what the reader has in front of them; the other suits a compact block seen in one piece.
In both cases look at the .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).
Not without touching the script: a counted card carries 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.