[removed] detect scroll end

2019-01-07 04:10发布

I have a div layer with overflow set to scroll.

When scrolled to the bottom of the div, I wanna run a function.


8条回答
beautiful°
2楼-- · 2019-01-07 04:54

Since innerHeight doesn't work in some old IE versions, clientHeight can be used:

$(window).scroll(function (e){
    var body = document.body;    
    //alert (body.clientHeight);
    var scrollTop = this.pageYOffset || body.scrollTop;
    if (body.scrollHeight - scrollTop === parseFloat(body.clientHeight)) {
        loadMoreNews();
    }
});
查看更多
在下西门庆
3楼-- · 2019-01-07 04:55

I could not get either of the above answers to work so here is a third option that works for me! (This is used with jQuery)

if (($(window).innerHeight() + $(window).scrollTop()) >= $("body").height()) {
    //do stuff
}

Hope this helps anyone!

查看更多
登录 后发表回答