zoukankan      html  css  js  c++  java
  • javascript平时小例子⑧(导航置顶效果)

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title></title>
    <style type="text/css">

    *{
    margin: 0;padding: 0;
    }
    .wrap{
    100%;
    height: 300px;
    position: relative;
    }
    .wrap .top{
    80%;
    margin:0 auto;
    height: 250px;
    background: red;
    }
    .wrap .bottom{
    80%;
    margin:0 auto;
    height: 50px;
    background: blue;
    }
    .wrap .fix{
    position: fixed;
    top: 0;
    left: 10%;
    }
    </style>
    </head>
    <body>
    <div id="wrap" class="wrap">
    <div id="top" class="top"></div>
    <div id="bottom" class="bottom"></div>
    </div>
    <div style="height: 2000px; 100%;"></div>
    <script>
    var wrap,tops,bottom;
    window.onload=function(){
    wrap=document.getElementById("wrap");
    tops=document.getElementById("top");
    bottom=document.getElementById("bottom");
    document.onscroll=function(){
    var scroll=document.body.scrollTop||document.documentElement.scrollTop;
    if(scroll>=tops.offsetHeight){
    bottom.classList.add("fix");
    }
    else{
    bottom.classList.remove("fix");
    }
    }
    }
    </script>
    </body>
    </html>

  • 相关阅读:
    深入源码之JDK Logging
    随机数生成器
    简单日志LogHelper
    Xml、Json序列化
    Redis封装之Set
    Redis封装之Hash
    Redis封装之String
    Redis之创建
    AngularJS初接触
    简单缓存Cache
  • 原文地址:https://www.cnblogs.com/cxy66/p/6050386.html
Copyright © 2011-2022 走看看