我正在使用jquery进行无限滚动,并尝试检测主div
的底部何时到达浏览器窗口的底部。我的问题是,在我的代码中,如果用户滚动太快,就不会在代码上触发相等。如何防止这种情况发生?
当用户滚动太快时,代码$(this).scrollTop() === exactPoint
不会触发。
下面是我如何执行该行为的一个示例。
http://jsfiddle.net/CCwYm/1/
我在这里用谷歌搜索了一下,但找不到对我有帮助的东西。
发布于 2016-05-17 22:54:42
由于您正在使用jQuery进行无限滚动页面,并且如果您的问题是在新内容更改文档高度之前无法正确检测页面的当前底部,请尝试如下所示(基于您的小提琴中的代码)
console.log($(document).height());
console.log($(window).height());
console.log($(document).height() - $(window).height())
var bottom = $(document).height() - $(window).height();
$(document).scroll(function(){
console.log($(this).scrollTop());
if ($(this).scrollTop() < bottom) {
console.log("scrolling");
} else {
alert("bottom");
$('.test').clone().appendTo( "body" );
bottom = $(document).height() - $(window).height();
}
});
.test{
width: 100px;
height: 1000px;
background-color: black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="test"></div>
https://stackoverflow.com/questions/37279226
复制相似问题