Advertisement
Guest User

Untitled

a guest
Dec 10th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. /* Counter - CountTo */
  3. $( document ).ready(function() {
  4.     var a = 0;
  5.     $(window).scroll(function() {
  6.         if ($('.count_up').length) { // checking if CountTo section exists in the page, if not it will not run the script and avoid errors 
  7.             var oTop = $('.count_up_holder').offset().top - window.innerHeight;
  8.             if (a == 0 && $(window).scrollTop() > oTop) {
  9.             $('.count_up').each(function() {
  10.                 var $this = $(this);
  11.                 count_classes = $this.attr('class');
  12.                 var res = count_classes.split(" ");
  13.                 var class_count = res.length;
  14.  
  15.                 var i = 0;
  16.                 while (i < class_count) {
  17.                     var class_name = res[i];
  18.                     if (class_name.indexOf('count_to') > -1) {
  19.                         var res2 = class_name.split("-");
  20.                         var countTo = res2[1];
  21.                     }
  22.                     i++;
  23.                 }
  24.  
  25.                 $({
  26.                 countNum: $this.text()
  27.                 }).animate({
  28.                     countNum: countTo
  29.                 },
  30.                 {
  31.                     duration: 2000,
  32.                     easing: 'swing',
  33.                     step: function() {
  34.                         var $target = $this.children();
  35.                         while( $target.length ) {
  36.                             $target = $target.children();
  37.                         }
  38.                         $target.end().text(Math.floor(this.countNum));
  39.                     },
  40.                     complete: function() {
  41.                         var $target = $this.children();
  42.                         while( $target.length ) {
  43.                             $target = $target.children();
  44.                         }
  45.                         $target.end().text(this.countNum);
  46.                     }
  47.                 });
  48.             });
  49.             a = 1;
  50.             }
  51.         }
  52.     });
  53. });
  54. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement