Skip to content

Instantly share code, notes, and snippets.

@PaulGwamanda
Last active April 16, 2020 04:52
Show Gist options
  • Save PaulGwamanda/58fcb400fb744757c7ccc19aa506d631 to your computer and use it in GitHub Desktop.
Save PaulGwamanda/58fcb400fb744757c7ccc19aa506d631 to your computer and use it in GitHub Desktop.
Jquery Count up numbers when scrolled into view
/** Jquery Count up numbers when scrolled into view
* <div class="col-lg-4 stats">
* <h3 class="">
* <span class="statvalue" numx="895"></span>
* </h3>
* <p class="lead">
* Since we started
* </p>
* </div>
* <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js" ></script>
* <script src="https://cdnjs.cloudflare.com/ajax/libs/waypoints/4.0.1/jquery.waypoints.js"></script>
* <script src="https://cdnjs.cloudflare.com/ajax/libs/countup.js/1.9.3/countUp.js"></script>
* **/
// jquery countup
var options = {
useEasing: true,
useGrouping: true,
separator: ',',
decimal: '.',
prefix: '',
suffix: ''
};
var counts = [];
$('.statvalue').each(function() {
var num = $(this).attr('numx'); //end count
var nuen = $(this).text();
if (nuen === "") {
nuen = 0;
}
counts.push(new CountUp(this, nuen, num, 0, 3, options));
});
var waypoint1 = new Waypoint({
element: document.getElementsByClassName("stats"),
handler: function(direction) {
if (direction == "up") {
for (var i = 0; i < counts.length; i++) {
counts[i].reset();
}
} else {
for (var i = 0; i < counts.length; i++) {
counts[i].start();
}
}
},
offset: "50%"
});
@bronze
Copy link

bronze commented Mar 13, 2019

could this be used with %?

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