Created
March 19, 2018 10:26
-
-
Save aaronsummers/887ae5a35d1ecdd24af5047367a14efe to your computer and use it in GitHub Desktop.
Js Count up
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
$('.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' }); |
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
<div class="number"> | |
<span class="counter"><?php echo $stat; ?></span> | |
<?php echo $stat_append; /* ex. '%' */?> | |
</div> |
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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download waypoints from https://github.com/imakewebthings/waypoints/tree/master/lib