Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery计数器正在计数到所需的数字,但随后也开始反向计数_Jquery - Fatal编程技术网

Jquery计数器正在计数到所需的数字,但随后也开始反向计数

Jquery计数器正在计数到所需的数字,但随后也开始反向计数,jquery,Jquery,这是我的jquery代码。它计数到给定的数字,然后开始反向计数。。。。我还在代码末尾添加了$('.count')。remove,但它不起作用 $(window).scroll(function(){ $('.count').each(function() { $(this).prop('Counter', 0).animate({ Counter: $(this).text() }, { duration: 4000, easing: 'swing', step: fu

这是我的jquery代码。它计数到给定的数字,然后开始反向计数。。。。我还在代码末尾添加了$('.count')。remove,但它不起作用

$(window).scroll(function(){

 $('.count').each(function() {

 $(this).prop('Counter', 0).animate({
  Counter: $(this).text()
 }, {
  duration: 4000,
  easing: 'swing',
  step: function(now) {
    $(this).text(Math.ceil(now));
   }         
  });
 });   
})

步骤之后使用
complete:

e、 g


好的,谢谢你的代码。你的DOM是什么样子的?你期望的输出是什么?你能发布你的html代码吗?这是我的html代码。1000在没有测试细节的情况下,我认为问题在于之前的动画从未停止过。滚动时,动画会多次启动。您可以尝试在each中使用
$(this).stop().prop(…etc
。(不知道它是否解决了当前的问题)我刚才提到了完整的函数。必须根据需要对其进行修改。
$({countNum: 0}).animate({countNum: 100}, {
    duration: 4000,
    easing:'linear',
    step: function() {
        $(this).text(Math.floor(this.countNum));
    },
    complete: function() {
        $(this).addClass('loaded');
    }
});