Javascript 数一数卷轴上的数字

Javascript 数一数卷轴上的数字,javascript,jquery,html,css,Javascript,Jquery,Html,Css,如果我向上滚动到数字,如何重新开始计数?我有一个计数的数字。我再向下滚动页面,然后再向上返回。我想再次看到从零开始的计数,可能吗 函数计数($this){ var current=parseInt($this.html(),10); 电流=电流+1; $this.html(++当前版本); 如果(当前>$this.data('count')){ $this.html($this.data('count')); }否则{ setTimeout(函数(){ 计数($this) }, 1); } }

如果我向上滚动到数字,如何重新开始计数?我有一个计数的数字。我再向下滚动页面,然后再向上返回。我想再次看到从零开始的计数,可能吗

函数计数($this){
var current=parseInt($this.html(),10);
电流=电流+1;
$this.html(++当前版本);
如果(当前>$this.data('count')){
$this.html($this.data('count'));
}否则{
setTimeout(函数(){
计数($this)
}, 1);
}
}
$(“.stat count”).each(函数(){
$(this.data('count',parseInt($(this.html(),10));
$(this.html('0');
计数($(此));
});
#计数器{
利润率下限:90%
}

400
第一
105
二号
321
三号

您可以使用jQuery检测滚动位置。一旦到达零位置,您将重新运行允许计数器的脚本。最好是在滚动到零位时调用函数,将每个都放入一个函数中

$(window).scroll(function (event) {
    var scroll = $(window).scrollTop();

    if(scroll == 0)
     setTimeout(function(){reInitCount();},500);
});

function reInitCount(){
  $(".stat-count").each(function() {
    $(this).html('0');
    count($(this));
  });
}
函数reInitCount(){
$(“.stat count”).each(函数(){
$(this.html('0');
计数($(此));
});
}
函数计数($this){
var current=parseInt($this.html(),10);
电流=电流+1;
$this.html(++当前版本);
如果(当前>$this.data('count')){
$this.html($this.data('count'));
}否则{
setTimeout(函数(){
计数($this)
}, 1);
}
}
重新计数();
$(窗口)。滚动(功能(事件){
var scroll=$(窗口).scrollTop();
如果(滚动==0)
setTimeout(函数(){reInitCount();},500);
});
#计数器{
利润率下限:90%
}

0
第一
0
二号
0
三号

……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……
……

我的意思是,每次滚动到数字时,我都想再数一次。但这不是偶然的欢迎,你能把答案标记为正确的plz来帮助其他和你有同样问题的人吗?为什么你不在窗口滚动事件中使用元素的偏移属性,我认为这是最简单的。你能给我举个例子吗?我想马哈茂德已经给了你一个在窗口上工作的解决方案,