Created
April 27, 2016 18:57
-
-
Save ashicus/b18f2831d7d21fc10fe2e47c41922328 to your computer and use it in GitHub Desktop.
Animate number counting
This file contains 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
function animate_count($el, duration, prefix, postfix, is_decimal) { | |
prefix = prefix || ''; | |
postfix = postfix || ''; | |
is_decimal = is_decimal || false; | |
var text = $el.text().replace(/[^0-9]/g, '') | |
jQuery({ counter: 0 }).animate({ counter: parseInt(text) }, { | |
duration: 1250, | |
easing: 'swing', | |
step: function () { | |
text = is_decimal ? Math.ceil(this.counter) / 100 : Math.ceil(this.counter); | |
$el.text(prefix + text + postfix); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment