移动端滑动加载

2016-06-26  本文已影响102人  一沭丶
function scrollLoad(){
   var scrollTop = 0;
   var clientHeight = 0;
   var scrollHeight = 0; 
   if (document.documentElement && document.documentElement.scrollTop) {  
            scrollTop = document.documentElement.scrollTop;  
      } else if (document.body) {
           scrollTop = document.body.scrollTop;  
     }
if (document.body.clientHeight && document.documentElement.clientHeight) {  
            clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight: document.documentElement.clientHeight;  
     } else {
             clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight: document.documentElement.clientHeight;  
     }
    // 知识点:Math.max 比较大小,取最大值返回  
scrollHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
     if (scrollTop + clientHeight +200 > scrollHeight) {
          //滑到底部时 do something...
       } else {
           return false;  
        }
}
上一篇 下一篇

猜你喜欢

热点阅读