JSFiddle - React, Tailwind, and code Playground
HTML
<h1 class="counter" data-count="1000000">0</h1>
<h1 class="counter" data-count="50">0</h1>
JavaScript
$( document ).ready(function() {
$('.counter').each(function () {
var $this = $(this),
countTo = $this.attr('data-count');
var animation = {
countNum: countTo
};
$({ countNum: $this.text() }).animate(animation, {
duration: 10000,
step: function (now, fx) {
$this.text(Math.floor(this.countNum));
if (fx.pos > 0.5) {
$(this).stop();
$(this).animate(animation, {
duration: 10000,
step: function () {
$this.text(Math.floor(this.countNum));
},
complete: function () {
$this.text(this.countNum);
}
});
}
}
});
});
});