我正在尝试制作一个网站,当用户开始滚动时,它会自动将它们滚动(而不是跳转)到设定的位置,以便可以看到内容。内容已经在页面上了,我只是不想让他们滚动到它,所以一旦他们开始向下移动页面,它就会通过滚动到设定点来帮助他们。
这是我到目前为止所拥有的,但我迷路了:
<script type="text/javascript">
$(body).scroll(function() {
if ( $this).scrollTop() > 1 ) {
}
});
</script>
最佳答案
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);
关于javascript - 检测滚动 - 滚动到 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20224354/