Last active
April 16, 2020 04:52
-
-
Save PaulGwamanda/58fcb400fb744757c7ccc19aa506d631 to your computer and use it in GitHub Desktop.
Jquery Count up numbers when scrolled into 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
/** 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%" | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
could this be used with %?