zoukankan      html  css  js  c++  java
  • 滚动监听

    function getScrollTop(){
      var 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;
    }
    //文档的总高度
    function getScrollHeight(){
      var 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;
    }
    //浏览器视口的高度
    function getWindowHeight(){
      var windowHeight = 0;
      if(document.compatMode == "CSS1Compat"){
        windowHeight = document.documentElement.clientHeight;
      }else{
        windowHeight = document.body.clientHeight;
      }
      return windowHeight;
    }
    window.onscroll = function(){
      if(getScrollTop() + getWindowHeight() == getScrollHeight()){
       document.getElementsByClassName('footer')[0].style.display='flex';
    }else{
    document.getElementsByClassName('footer')[0].style.display='none';
      }
    };
    document.getElementsByClassName('footer')[0].onclick=function(){
    document.body.scrollTop=0;
    }

  • 相关阅读:
    webpack常用插件及作用
    函数柯里化
    防抖和节流
    实现深拷贝
    实现new操作符
    关于js中断ajax请求
    从输入 URL 到页面加载完成,发生了什么?
    vue路由传参params和query的区别
    input输入框限制(座机,手机号码)
    判断当前页面是不是用户正在浏览的页面
  • 原文地址:https://www.cnblogs.com/QxkWeb/p/7488100.html
Copyright © 2011-2022 走看看