zoukankan      html  css  js  c++  java
  • 网页滚动到顶部或底部加载

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
          *{
              margin:0px;
              padding:0px;
          }
          body{
              100%;
              height:2000px;
              position:relative;
          }
          div{
          
              500px;
              height:500px;
              border:1px solid red;
              background: red;
            position:absolute;

            
          }
        </style>
        <script>
           function scroll(){
               var client=document.documentElement.clientHeight||window.innerHeight||document.body.clientHeight;//元素的高度==$(window).height()
               var scrollTop=document.body.scrollTop;//被卷上去的部分==$(window).scrollTop()/$(body).scrollTop()
               var wholeHeight=document.body.scrollHeight;//元素内容的高度==$(document).height()
               if(client+scrollTop>=wholeHeight){
                   var div=document.getElementsByTagName("div")[0];              
                   div.style.transition="3s";
                   div.style.transform="translate(500px,1500px)";//平移是相对元素当前位置进行移动 sLeft = div.style.transform ? -parseInt(/d+/.exec(div.style.transform)[0]) : 0;获取元素的位移值
                 console.log("已经滚动到底部")
                   
               }else if(scrollTop==0){
                   var div=document.getElementsByTagName("div")[0];  

                   div.style.transition="3s";
                   div.style.transform="translate(0px,0px)";//平移是相对元素当前位置进行移动
                   console.log("已经滚动到顶部")
                   
               }
           }
           window.onscroll=scroll;


        </script>
    </head>
    <body>
      <div></div>
        
    </body>
    </html>

  • 相关阅读:
    swift 第十四课 可视化view: @IBDesignable 、@IBInspectable
    swift 第十三课 GCD 的介绍和使用
    swift 第十二课 as 的使用方法
    swift 第十一课 结构体定义model类
    swift 第十课 cocopod 网络请求 Alamofire
    swift 第九课 用tableview 做一个下拉菜单Menu
    swift 第八课 CollectView的 添加 footerView 、headerView
    swift 第七课 xib 约束的优先级
    swift 第六课 scrollview xib 的使用
    swift 第五课 定义model类 和 导航栏隐藏返回标题
  • 原文地址:https://www.cnblogs.com/huangshikun/p/6649317.html
Copyright © 2011-2022 走看看