StealThis .dev

Smooth Number Counter

Stats that count up when they scroll into view. Powered by GSAP ScrollTrigger with eased number interpolation.

Open in Lab
gsap scrolltrigger
Targets: JS HTML

Code

Smooth Number Counter

Stat numbers that animate from zero to their target value as they scroll into the viewport. Uses GSAP’s ScrollTrigger for the trigger and gsap.to() with a proxy object for smooth eased interpolation.

How it works

Each counter element stores its target in a data-target attribute. GSAP animates a plain object { val: 0 } to { val: target } and updates the DOM in onUpdate:

gsap.to(obj, {
  val: target,
  duration: 2,
  ease: "power2.out",
  onUpdate: () => el.textContent = Math.round(obj.val).toLocaleString(),
  scrollTrigger: { trigger: el, start: "top 85%" }
});

Features

  • toLocaleString() formats large numbers with commas (1,000+)
  • Suffix support via data-suffix (%, K, +, ms…)
  • prefers-reduced-motion — skips to final value instantly