Skip to content

Instantly share code, notes, and snippets.

@ashicus
Created April 27, 2016 18:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashicus/b18f2831d7d21fc10fe2e47c41922328 to your computer and use it in GitHub Desktop.
Save ashicus/b18f2831d7d21fc10fe2e47c41922328 to your computer and use it in GitHub Desktop.
Animate number counting
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