Created
May 8, 2016 03:40
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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