zoukankan      html  css  js  c++  java
  • 菜单滚动至顶部后固定

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>菜单滚动至顶部后固定-柯乐义</title>
    <style type="text/css">
    .wrapper{1000px;height:2000px;margin-left:auto;margin-right:auto;}
    .header{height:150px;}
    #nav_keleyi_com{padding:10px;position:relative;top:0;background:#125430;1000px;}
    a{display:inline-block;margin:0 10px;*display:inline;zoom:1;color:white;}
    </style>
    </head>
    <body>
    <div class="wrapper">
    <div class="header"></div>
    <div id="nav_keleyi_com">
    <a href="http://keleyi.com/menu/net/" target="_blank">.NET</a>
    <a href="http://keleyi.com/menu/javascript/" target="_blank">Javascript</a>
    <a href="http://keleyi.com/menu/jquery/" target="_blank">jQuery</a>
    <a href="http://keleyi.com/menu/csharp/" target="_blank">C#</a>
    <a href="http://keleyi.com/menu/other/" target="_blank">其他</a>
    <a href="http://keleyi.com/" target="_blank">首页</a><a href="/menu/aspnet/" 

    target="_blank">ASP.NET</a> <a href="/menu/mvc/" target="_blank">MVC</a></div>
    </div>
    <script type="text/javascript" >
    function menuFixed(id){
    var obj = document.getElementById(id);
    var _getHeight = obj.offsetTop;

    window.onscroll = function(){
    changePos(id,_getHeight);
    }
    }
    function changePos(id,height){
    var obj = document.getElementById(id);
    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    if(scrollTop < height){
    obj.style.position = 'relative';
    }else{
    obj.style.position = 'fixed';
    }
    }
    </script>
    <script type="text/javascript">
    window.onload = function(){
    menuFixed('nav_keleyi_com');
    }
    </script>
    </body>
    </html>

    此文摘要自:http://keleyi.com/a/bjac/5d7f4ac2efa72d30.htm

  • 相关阅读:
    iPhone 调用Web Service 例子(转)
    iPhone开发:在UIAlertView中显示进度条(转)
    Oracel 分页
    NYOJ 477
    NYOJ 108(数组中存的是前n个数的和)
    NYOJ 199
    NYOJ 311(完全背包)
    高效斐数(前92位)
    NYOJ 57(6174问题)
    NYOJ 546(分珠宝)
  • 原文地址:https://www.cnblogs.com/lc23/p/5394868.html
Copyright © 2011-2022 走看看