Skip to content

Instantly share code, notes, and snippets.

@aaronsummers
Created March 19, 2018 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronsummers/887ae5a35d1ecdd24af5047367a14efe to your computer and use it in GitHub Desktop.
Save aaronsummers/887ae5a35d1ecdd24af5047367a14efe to your computer and use it in GitHub Desktop.
Js Count up
$('.number').waypoint(function(){
function startCounter(){
$('.counter').each(function (index) {
var size = $(this).text().split(".")[1] ? $(this).text().split(".")[1].length : 0;
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 5000,
easing: 'swing',
step: function (now) {
$(this).text(parseFloat(now).toFixed(size));
$(this).removeClass('counter'); // Remove the class so we only count once
}
});
});
}
startCounter();
}, { offset: 'bottom-in-view' });
<div class="number">
<span class="counter"><?php echo $stat; ?></span>
<?php echo $stat_append; /* ex. '%' */?>
</div>
wp_enqueue_script( 'waypoints', get_template_directory_uri() . '/assets/js/jquery.waypoints.min.js', array( 'jquery' ), filemtime( get_stylesheet_directory() . '/assets/js/jquery.waypoints.min.js' ), true);
@aaronsummers
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment