滚动触发计数器动画

时间:2019-04-03 16:24:26

标签: javascript jquery bootstrap-4

我找到了这个计数器代码的示例,但是我试图在滚动时启动计数器。滚动时如何激活计数器的动画?

https://jsfiddle.net/4z0wbLoh/3/

谢谢。

$.fn.jQuerySimpleCounter = function( options ) {
      var settings = $.extend({
          start:  0,
          end:    100,
          easing: 'swing',
          duration: 400,
          complete: ''
      }, options );

      var thisElement = $(this);

      $({count: settings.start}).animate({count: settings.end}, {
      duration: settings.duration,
      easing: settings.easing,
      step: function() {
        var mathCount = Math.ceil(this.count);
        thisElement.text(mathCount);
      },
      complete: settings.complete
    });
  };


$('#number1').jQuerySimpleCounter({end: 450,duration: 3000});
$('#number2').jQuerySimpleCounter({end: 20,duration: 3000});
$('#number3').jQuerySimpleCounter({end: 700,duration: 2000});
$('#number4').jQuerySimpleCounter({end: 8,duration: 2500});

0 个答案:

没有答案