1

I have so far created
1. When an row is in view that elements slide in
2. Counters that counts up to a number.

I would like to improve no 2 so that counters start only when in view and also that they don't all go off at once but first on the left to start then when it finishes next counter to go off and so on.

Can someone please help me ?

This is my jsfiddle that i created with the same code: https://jsfiddle.net/DTcHh/32842/

        //window and animation items
        var animation_elements = $.find('.animation-element');
        var web_window = $(window);

        //check to see if any animation containers are currently in view
        function check_if_in_view() {
        //get current window information
        var window_height = web_window.height();
        var window_top_position = web_window.scrollTop();
        var window_bottom_position = (window_top_position + window_height);

        //iterate through elements to see if its in view
        $.each(animation_elements, function() {

          //get the element information
          var element = $(this);
          var element_height = $(element).outerHeight();
          var element_top_position = $(element).offset().top;
          var element_bottom_position = (element_top_position + element_height);

          //check to see if this current container is visible (its viewable if it exists between the viewable space of the viewport)
          if ((element_bottom_position >= window_top_position) && (element_top_position <= window_bottom_position)) {
            element.addClass('in-view');
          } else {
            element.removeClass('in-view');
          }
        });

        }

        //on or scroll, detect elements in view
        $(window).on('scroll resize', function() {
          check_if_in_view()
        })
        //trigger our scroll event on initial load
        $(window).trigger('scroll');



        //Counter
        $('.counter').each(function() {
          var $this = $(this),
              countTo = $this.attr('data-count');

          $({ countNum: $this.text()}).animate({
            countNum: countTo
          },

          {
            duration: 8000,
            easing:'linear',
            step: function() {
              $this.text(Math.floor(this.countNum));
            },
            complete: function() {
              $this.text(this.countNum);
              //alert('finished');
            }
          });  
        });
    });
Stack ant
  • 51
  • 7

1 Answers1

0

You can user counter up js by downloading from this link

https://www.npmjs.com/package/jquery.counterup

you just need to include below js

<script src="https://cdnjs.cloudflare.com/ajax/libs/waypoints/4.0.0/jquery.waypoints.min.js"></script>
<script src="jquery.counterup.min.js"></script>

and the counter span

<span class="counter" data-counterup-time="1500" data-counterup-delay="30" data-counterup-beginat="100">1,234,567.00</span>

and then counterup js

$('.counter').counterUp();

hope this help you

Jalay Oza
  • 772
  • 7
  • 11
  • Thank you for help ! :) One more question. When i set a higher data-counterup-delay then after delay it jumps straight to the final number instead of counting up. Do you maybe know why this happens? – Stack ant May 19 '17 at 14:20