我在读哈佛商业评论( Harvard Business Review )的博客文章 (2011-02-22)。他们在纽约时报( The New York Times )上也这样做。当你的阅读器一直滚动到底部时,你如何检测到呢?
在HBR上,当你滚动到接近底部的位置时,他们会提供另一篇文章供你阅读。
发布于 2011-02-23 10:39:17
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height()-$(window).height()){
alert("We're at the bottom of the page!!");
}
});
发布于 2011-02-24 09:22:17
虽然另一个答案会告诉你什么时候你在底部,为了回答你关于如何判断你接近底部的问题,我以前用过这个:
if ( ($(document).height() - $(window).height()) - $(window).scrollTop() < 1000 ){
//do stuff
}
您可以将值"1000“更改为您想要的任何值,以便在您离底部有那么多像素时触发脚本。
发布于 2011-03-01 16:03:44
$(window).scroll(function () {
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 10) {
alert('end of page');
}
});
-10表示在函数执行前用户必须离页末多远。这使您可以根据需要灵活地调整行为。
在http://jsfiddle.net/wQfMx/查看工作示例
https://stackoverflow.com/questions/5086401
复制相似问题