、document.documentElement.scrollTop和document.body.scrollTop始终有一个为0,所以可以用这两个的和来求scrollTop
2、scrollHeight、clientHeight 在DTD已声明的情况下用documentElement,未声明的情况下用body
所以,判断滚动条是否已拉到页面最底部,可以用如下代码:
window.onscroll = function (){
var marginBot = 0;
if (document.compatMode === "CSS1Compat"){
marginBot = document.documentElement.scrollHeight
- (document.documentElement.scrollTop+document.body.scrollTop)
- document.documentElement.clientHeight;
}
else {
marginBot = document.body.scrollHeight
- document.body.scrollTop
- document.body.clientHeight;
}
if(marginBot<=0) {
//do something
}
}