htmlbeginnermit

Number Counter

Numbers count up when they appear.

7.5k2.4k354244

About this module

A statistic counter that animates from zero to its target using GSAP's innerText snapper.

#gsap#counter#numbers#stats

Source code

Installation

  1. 1

    Install GSAP

    Install the animation library with your package manager.

    npm install gsap
  2. 2

    Create the files

    Create `index.html`, `style.css` and `script.js` in the same folder.

  3. 3

    Paste the code

    Copy each file's source into its matching file.

  4. 4

    Run it

    Open `index.html` (or import the logic into your bundler setup).

Usage

  1. 1

    Copy the HTML

    Paste the markup where you need it.

    <link rel="stylesheet" href="style.css" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/gsap.min.js"></script>
    <script src="script.js"></script>
    <div class="mh-counters">
      <div><span class="mh-count" data-target="1200">0</span><small>Modules</small></div>
      <div><span class="mh-count" data-target="3200000">0</span><small>Copies</small></div>
    </div>
  2. 2

    Paste the script

    Include `script.js` after GSAP.

    document.querySelectorAll(".mh-count").forEach((el) => {
      const target = Number(el.dataset.target);
      const obj = { val: 0 };
      gsap.to(obj, {
        val: target,
        duration: 1.6,
        ease: "power2.out",
        onUpdate: () => {
          el.textContent = Math.round(obj.val).toLocaleString("en-US");
        },
      });
    });
Overview
Categoryanimations
Frameworkhtml
Difficultybeginner
Licensemit
Versionv1.0.0
Features
  • Powered by GSAP
  • GPU-accelerated transforms
  • Pauseable timeline
Traits
  • ResponsiveYes
  • Dark modeYes
  • AccessibleYes
  • Production readyYes
Dependencies
gsap@^3.12
Browser support
  • Chrome 90+
  • Firefox 90+
  • Safari 15+
  • Edge 90+

Related modules

Command Palette

Search modules and jump anywhere