下拉刷新

let _self = this; window.addEventListener('scroll', () => { handler.winScroll(function () { if (_self.state.hasData) { _self.requestDoctorListApi(); } }); });瀏覽器

export const handler = { winScroll: function (callback) { let scrollTop, scrollHeight, clientHeight; scrollTop = this.getScrollTop(); scrollHeight = this.getScrollHeight(); clientHeight = this.getClientHeight();this

if(scrollTop + clientHeight >= scrollHeight-15){
        callback && callback();               
    }  
},
getScrollTop: function(){
  let scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
  if(document.body){
    bodyScrollTop = document.body.scrollTop;
  }
  if(document.documentElement){
    documentScrollTop = document.documentElement.scrollTop;
  }
  scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
  return scrollTop;
},
    
//文檔的總高度     
getScrollHeight: function(){
  let scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
  if(document.body){
    bodyScrollHeight = document.body.scrollHeight;
  }
  if(document.documentElement){
    documentScrollHeight = document.documentElement.scrollHeight;
  }
  scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
  return scrollHeight;
},
    
//瀏覽器視口的高度     
getClientHeight: function(){
  let clientHeight = 0;
  if(document.compatMode == "CSS1Compat"){
        clientHeight = document.documentElement.clientHeight;
  }else{
        clientHeight = document.body.clientHeight;
  }
  return clientHeight;
}

}code

相關文章
相關標籤/搜索