JSFiddle - React, Tailwind, and code Playground

by jakelauer

HTML

<div></div>

JavaScript

$.fn.countup = function (num, time, start) {
	return this.each(function () {
        start = (typeof start == 'undefined') ? 0 : start;
        var $this = $(this);
        var numPer = (num > time) ? Math.floor(num / time) : (time/num);
        var int = setInterval(function(){
            $this.text(pad(start += numPer, num.length).split('.')[0])                    
        }, 1);
        setTimeout(function(){
            clearInterval(int)
            $this.text(num)                
        }, time)
        
        function pad(num, size) {
            var s = num+"";
            while (s.length < size) s = "0" + s;
            return s;
        }
	})
}

$('div').countup(3, 500)