我正在通过滚动实现按需加载数据。
我已经在document.ready中为div注册了该函数。
只有当滚动条到达最后一个滚动条时,才应填充数据。因此,为了确定滚动是否已经到了最后,我使用了下面的函数。
$("#tree").scroll(function () {
if (isScrolledToBottom(this)) {
}
});但是函数没有返回正确的值。我的意思是,当scroll到达它的最后一个时,它应该返回一个真值。
function isScrolledToBottom(object) {
return ($(object).attr('scrollHeight') - $(object).scrollTop() - 1) <= $(object).height();
};发布于 2012-03-12 18:04:14
试着这样做:
return ($(object).attr('offsetHeight') + $(object).attr('scrollTop') >= $(object).attr('scrollHeight'));发布于 2012-03-12 18:06:14
如果你想无限滚动,请查看我的答案:How to load the web page content based on user scrolling
此演示在某个Y滚动位置触发。如果您希望在用户到达某个项目时实现这一点,您可能需要查看Waypoints插件。
http://imakewebthings.com/jquery-waypoints/
无限滚动演示:http://imakewebthings.com/jquery-waypoints/infinite-scroll/
$('.theItems:last').waypoint(function(event, direction) {
//Ajax fetch here
});发布于 2017-02-17 20:22:07
var scrollHeight = $(object).prop("scrollHeight"); // total scrollable height of the element
var scrollTop = $(object).scrollTop(); // how far you have come from the top while scrolling vertically
var height = $(object).height(); // the constant height of the portion in display at all times
if (scrollHeight === (scrollTop + height)) {
//console.log("fetching page");
fetchNextPage();
}https://stackoverflow.com/questions/9664796
复制相似问题