【发布时间】:2014-01-14 06:27:32
【问题描述】:
我正准备在我们网站的仪表板上开发无限滚动,但是我目前对如何在我的jsfiddle mockup 中确定容器 div 的底部感到困惑。
原始功能,适用于没有容器div的空白页面
var wireInfinScroll = function() {
console.log('in wireInfinScroll');
$('#scroll_screen').scroll(function(){
console.log('scrolling...');
console.log(' ');
//if ($('#scroll_screen').scrollTop() == $('#content').height() - $('#scroll_screen').outerHeight()) {
if ($('#scroll_screen').scrollTop() == $('#content').height() - $('#scroll_screen').height()) {
// run our call for pagination
console.log('Bottom of Page!');
alert('Bottom of Page!');
}
});
}
wireInfinScroll();
CSS
#scroll_screen {
overflow-y: auto;
background: pink;
}
我尝试在示例中将 window 替换为正在滚动的 div (#scroll_screen),但无法触发警报。
你会如何解决这个问题?
更新
-
注意,我在这里使用相同的代码创建了一个新的 jsFiddle: http://jsfiddle.net/leonwho/L9A6Q/
-
我还注意到,除非我单击内部,否则我的 console.logs 永远不会显示
#scroll_screendiv? -
删除了 Codepen,使用 jsFiddle 更进一步,使用
$('#scroll_screen').scroll(function(){ -
注意!当我从
#contentdiv 中删除height: 100%,然后向下滚动并返回时,我终于得到了我的警报,但这仍然不正确。 警报应该在向下滚动时发生
css
#content {
float: right;
width: 79%;
//height: 100%;
background: #f8f8f8;
}
【问题讨论】:
-
$(window).height() - $(window).height()将始终为 0 -
啊抱歉,原来是window.scrollTop == document.height - window.height
-
那个链接上什么都没有,你介意用Fiddle吗,它更可靠,因为我想我知道答案了! (不是发布的内容)
-
@LeonGaban 我需要看看你的 CSS,我在 body 上看到了类似
100%的东西,所以我需要看看删除它是否有效。此外,您的 HTML 中有很多错误。 -
添加了新的注释并刚刚创建了 jsfiddle jsfiddle.net/leonwho/L9A6Q
标签: javascript jquery html infinite-scroll