Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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 检测滚动-滚动到div_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 检测滚动-滚动到div

Javascript 检测滚动-滚动到div,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在尝试创建一个站点,当用户开始滚动时,它会自动将他们滚动(而不是跳转)到一个设置的位置,这样就可以看到内容。内容已经在页面上了,我只是不希望他们滚动到它,所以一旦他们开始向下移动页面,它将帮助他们滚动到一个设定点 这就是我到目前为止所拥有的,但我迷路了: <script type="text/javascript"> $(body).scroll(function() { if ( $this).scrollTop() > 1 ) { } }); <

我正在尝试创建一个站点,当用户开始滚动时,它会自动将他们滚动(而不是跳转)到一个设置的位置,这样就可以看到内容。内容已经在页面上了,我只是不希望他们滚动到它,所以一旦他们开始向下移动页面,它将帮助他们滚动到一个设定点

这就是我到目前为止所拥有的,但我迷路了:

<script type="text/javascript">
$(body).scroll(function() {
    if ( $this).scrollTop() > 1 ) {

    }
});
</script> 

$(正文)。滚动(函数(){
如果($this).scrollTop()>1){
}
});

您可以将元素绑定到scrollstart(还有一个scrollstop)事件:


您可以将元素绑定到scrollstart(还有一个scrollstop)事件:


这真是可爱的效果:p@user2598957我已经更新了脚本。动画完成后,将启用滚动。然后由您检查滚动位置是否为0,以重新连接侦听器。这是一个非常聪明的解决方案:D+1!这真是可爱的效果:p@user2598957我已经更新了脚本。动画完成后,将启用滚动。然后由您检查滚动位置是否为0,以重新连接侦听器。这是一个非常聪明的解决方案:D+1!您已经链接到jQuery mobile的“文档”,我不认为OP的问题只是移动。Scrollstart在jQuery中不存在,您需要插件:您已经链接到jQuery mobile的“文档”,我不认为OP的问题只是移动。jQuery中不存在Scrollstart,您需要插件:
jQuery('#yourElementId').bind("scrollstart",scrollFunc);

var scrollFunc = function(){
  //if(jQuery('#yourElementId').scrollTop()>1) //unnecessary 
  jQuery('#yourElementId').scrollTop(300); // change 300 to any number you want
}
var scrollFunction = function() {
    $('html, body').not(':animated').animate({
        scrollTop: $("#layer-2").offset().top //gets the position of the next layer
    }, 1000, function() {
        $(document).off('scroll', scrollFunction)
    });
}

$(document).on('scroll', scrollFunction);