Skip to content

Instantly share code, notes, and snippets.

@martin-sweeny
Created May 8, 2016 03:40
Show Gist options
  • Save martin-sweeny/adfee0d7802b16729d09f377abd35122 to your computer and use it in GitHub Desktop.
Save martin-sweeny/adfee0d7802b16729d09f377abd35122 to your computer and use it in GitHub Desktop.
A miniscule plugin to allow an element to "count up" to a number
$.fn.countUp = function(timing) {
var max = parseInt(this.text());
if ( !max ) return false;
var i = 0;
var $this = this;
var delay = timing / max ;
var intv = setInterval(function() {
$this.text(i);
if (i === max) return clearInterval(intv);
i++;
}, delay);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment