【发布时间】:2012-06-27 02:01:03
【问题描述】:
我正在尝试使用此问题Check if a user has scrolled to the bottom 中给出的代码向页面添加无限滚动功能,但是当我滚动到页面底部时没有任何反应。这是代码,因此您不必点击链接:
<script type="text/javascript">
alert("popup!");
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
alert("bottom!");
}
});
</script>
我添加了第一个警报以检查它是否只是我的浏览器阻止警报,但它显示正常。服务器还安装了 JQuery 1.7.2 min 并且页面是正确的,所以我认为这不是安装问题。
【问题讨论】:
-
尝试将
console.log($(window).height()+"<-current sctoll | target->"+($(document).height() - 100))放入该循环中,在 chrome 中打开它并右键单击 -> 元素检查器,打开控制台选项卡,它会告诉您每个循环的值是什么,应该可以帮助您诊断问题。如果您没有得到任何跟踪,则事件没有触发。 -
它对我来说似乎很好用.. jsfiddle.net/FLarv
-
在控制台选项卡中,我收到了
Uncaught ReferenceError: $ is not defined -
我添加了一个可能有帮助的答案。
标签: javascript jquery infinite-scroll