• 滚动监听


    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;
    }

  • 相关阅读:
    eslient配置
    webpack实战——手写常用plugin
    自己实现一个大文件切片上传+断点续传
    小程序长列表优化实践
    GitKraken 正體中文
    ruby Sequel 连接 PostgreSQL
    安装 Window Terminal 并连接wsl的Ubuntu系统
    ruby sinatra+puma+Nginx by Ubuntu
    ruby symbol 用法(:变量)
    win10配置子系统Ubuntu子系统(无需通过Windows应用市场)
  • 原文地址:https://www.cnblogs.com/QxkWeb/p/7488100.html
Copyright © 2020-2023  润新知