Animated counter

I’m using a counter that animates to a given number once the user scrolls to the div. Here is the CodePen: https://codepen.io/bmcdesign/pen/GRrBwbd

How can I add commas to the number counter? (ex. “300,000”)

If I add commas to the data-count, it returns as not a number.

Thanks to whoever can help me! :slight_smile:

Here you go…

step: function() {
            $this.text(Math.floor(this.countNum).toLocaleString());
          },
          complete: function() {
            $this.text(this.countNum.toLocaleString());
            //alert('finished');
          }

Using toLocaleString will use commas for everywhere it uses them, and I believe periods for those locales that use them too. Either way, it uses the separators. Notice above how we use toLocaleString on the counts.

2 Likes

Worked perfectly! Thanks! :slight_smile: