Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- /* Counter - CountTo */
- $( document ).ready(function() {
- var a = 0;
- $(window).scroll(function() {
- if ($('.count_up').length) { // checking if CountTo section exists in the page, if not it will not run the script and avoid errors
- var oTop = $('.count_up_holder').offset().top - window.innerHeight;
- if (a == 0 && $(window).scrollTop() > oTop) {
- $('.count_up').each(function() {
- var $this = $(this);
- count_classes = $this.attr('class');
- var res = count_classes.split(" ");
- var class_count = res.length;
- var i = 0;
- while (i < class_count) {
- var class_name = res[i];
- if (class_name.indexOf('count_to') > -1) {
- var res2 = class_name.split("-");
- var countTo = res2[1];
- }
- i++;
- }
- $({
- countNum: $this.text()
- }).animate({
- countNum: countTo
- },
- {
- duration: 2000,
- easing: 'swing',
- step: function() {
- var $target = $this.children();
- while( $target.length ) {
- $target = $target.children();
- }
- $target.end().text(Math.floor(this.countNum));
- },
- complete: function() {
- var $target = $this.children();
- while( $target.length ) {
- $target = $target.children();
- }
- $target.end().text(this.countNum);
- }
- });
- });
- a = 1;
- }
- }
- });
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement