JavaScript 获取浏览器窗口可视范围的高度,获取窗口滚动条滚动高度

获取浏览器窗口可视范围的高度
getClientHeight(){
      let clientHeight=0;
      if(document.body.clientHeight&&document.documentElement.clientHeight){
        clientHeight = (document.body.clientHeight.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
      }
      else{
        clientHeight = (document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
      }
      return clientHeight;
    },
获取浏览器窗口滚动条滚动高度
getScrollTop(){
  let scrollTop=0;
  if(document.documentElement&&document.documentElement.scrollTop){
    scrollTop=document.documentElement.scrollTop;
  }else if(document.body){
    scrollTop=document.body.scrollTop;
  }
  return scrollTop;
}

你可能感兴趣的:(js)