原理:文档高度 = 视口高度 + 滚动条高度
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){
//滚动到底部
}
});
});