2012-02-28 94 views
2

只有当我通过滚动到达div的底部时,我才需要在div内加载数据。从服务器加载数据,同时滚动Div到底部

我们面临的问题是$('div')。scrollHeight()和$('div')。scrollTop()值到达底部时不相同,所以我无法确定滚动到达底部或不。

如何识别div卷到底部附近(或可能是底部减去一定长度)?

请咨询......

注:基本上我试图做同样喜欢Facebook的股票。

问候, 纳文

回答

2

网络上有很多卷轴样本,下面的代码是从this one

... 
    if(container.scrollTop+container.clientHeight == container.scrollHeight){ 
       startRow = parseInt(startRow) + 10; 
       getData(); 
    } 
... 

希望有帮助。

1

继承人的jsfiddle scroll它使用scrollTop的+ clientHeight来比较scrollHeight属性。看看它是否适合你,在Mootools中很抱歉,但它非常简单。

function HandleScroll() 
{ 
    var el = $("outer"); 
    if((el.scrollTop + el.clientHeight) >= el.scrollHeight) 
    { 
     el.setStyles({ "background-color": "red"}); 
    } 
    else 
    { 
     el.setStyles({ "background-color": "white"}); 
    } 
} 
1

我建议您获取文档高度,并将该高度用作页面顶部到底部之间的长度。所以:

var bottom = $(document).height() // == the bottom of your page 

你可以减去与底部距离,你的愿望。

If((el.scrollTop() + el.outherHeight) >= (bottom - 200)){ 
    // fetch new data 

    // Don't forget to upate the bottom variable when data fetched and renderd 
} 

希望这可以解决您的问题,或者至少帮助您找到解决方案。如果没有,请让我知道