Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.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
Javascript 如何检测滚动结束_Javascript_Jquery_Scroll - Fatal编程技术网

Javascript 如何检测滚动结束

Javascript 如何检测滚动结束,javascript,jquery,scroll,Javascript,Jquery,Scroll,我的脚本有一些问题。所以,我想检测滚动动作的结束。我在滚动时有警报,但在结束时没有。你能帮助我吗?这是我的代码: var animatable = $('body, html'); var animating = false; animatable.animate( {scrollTop: $('#foo').offset()}) $(window).scroll(function(e) { if(!animating){ animatable.stop(

我的脚本有一些问题。所以,我想检测滚动动作的结束。我在滚动时有警报,但在结束时没有。你能帮助我吗?这是我的代码:

var animatable = $('body, html');
var animating = false;
animatable.animate( {scrollTop: $('#foo').offset()})

$(window).scroll(function(e) { 
       if(!animating){
           animatable.stop(false, true); 
           alert('stop scrolling');
       }
       animating = false;
});​

还有一些小提琴:

这就是你想要达到的目标:

$('body').animate( {scrollTop: $('#foo').offset().top},1000,function(){
 alert('stop scrolling');   
});

如果使用jquery设置滚动动画,则不必观看滚动事件


好的,如果您想检测用户何时停止滚动,您必须使用超时来检查用户是否停止滚动。否则,您将获得每个滚动步骤的事件。 像这样:

var delay = 1000;
var timeout = null;
$(window).bind('scroll',function(){
    clearTimeout(timeout);
    timeout = setTimeout(function(){
        alert('scrolling stopped');
    },delay);
});​​​​​​​​​​

可能会添加如下新事件:


将有助于

可能重复的no dude,我不想在我的网站底部提醒,但在滚动操作结束时,这是巨大的不同,但可能重复的no,我需要检测我的滚动操作停止,我在页面上,我开始滚动,滚动一些空间后我停止,所以我需要检测到那个时刻——当我在@ukaszBorawski结束它的时候,不清楚从你的问题和代码样本中你到底想做什么。但我已经更新了我的答案。