判断滚动条滚到底部

原理:文档高度 = 视口高度 + 滚动条高度

1.若是一整个浏览窗口的滚动条:

$(window).scroll(function () {
var documentHeight = $(document).height();//1188
var windowHeight = $(window).height();//706
var scrollTop = $(document).scrollTop();//482
var sh = windowHeight + scrollTop ;
console.log("sh="+sh+"documentHeight="+documentHeight);
    if(windowHeight+scrollTop ==  documentHeight){
//滚动到底部
}
});
或者
$(document).scroll(function () {
var documentHeight = $(document).height();//1188
var windowHeight = $(window).height();//706
var scrollTop = $(document).scrollTop();//482
var sh = windowHeight + scrollTop ;
console.log("sh="+sh+"documentHeight="+documentHeight);
    if(windowHeight+scrollTop ==  documentHeight){
//滚动到底部
}

});
2.若是某个div的滚动条:
$(document).ready(function () {
$(".tongModalBox").scroll(function () {
var documentHeight = $(this).prop('scrollHeight');//或$(this)[0].scrollHeight
var windowHeight = $(this).height();
var scrollTop = $(this).scrollTop();
var sh = windowHeight + scrollTop ;
console.log("sh="+sh+"documentHeight="+documentHeight);
        if(windowHeight+scrollTop ==  documentHeight){
//滚动到底部
}

});
});
posted @ 2018-11-16 18:18  雨夜稻草  阅读(499)  评论(0)    收藏  举报