上拉加载更多工具函数:
function getScrollTop(){
var scrollTop=0;
var bScrollTop=0;
var dScrollTop=0;
if(document.body){
bScrollTop=document.body.scrollTop;
}
if(document.documentElement){
dScrollTop=document.documentElement.scrollTop;
}
scrollTop=(bScrollTop-dScrollTop>0) ? bScrollTop : dScrollTop;
return scrollTop;
}
function getScrollHeight(){
var scrollHeight=0;
var bScrollHeight=0;
var dScrollHeight=0;
if(document.body){
bScrollHeight=document.body.scrollHeight;
}
if(document.documentElement){
dScrollHeight=document.documentElement.scrollHeight;
}
scrollHeight=(bScrollHeight-dScrollHeight>0) ? bScrollHeight : dScrollHeight;
return scrollHeight;
}
function getWindowHeight(){
var windowHeight=0;
if(document.compatMode=="CSS1Compat"){
windowHeight=document.documentElement.clientHeight;
}else{
windowHeight=document.body.clientHeight;
}
return windowHeight;
}
判断检测触底了
function scrollToBottom(callBack){
if(getScrollTop()+getWindowHeight()===getScrollHeight()){
callBack && callBack();
}
}