最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JS滾動(dòng)到指定位置導(dǎo)航欄固定頂部

 更新時(shí)間:2017年07月03日 15:48:36   作者:一個(gè)奕  
最近整理一下之前做的一個(gè)項(xiàng)目,把滾動(dòng)條動(dòng)態(tài)固定頂部的代碼整理出來和大家分享

最近整理一下之前做的一個(gè)項(xiàng)目,把滾動(dòng)條動(dòng)態(tài)固定頂部的代碼整理出來和大家分享,上代碼

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>js滾動(dòng)到指定位置導(dǎo)航欄固定頂部</title>
    <style type="text/css">
       body{height: 2500px; margin: 0; padding: 0;}
      .banner{height: 250px; width: 100%; background: #e5e5e5;}
      .bignav{width: 100%; background: #000;}
      .nav{ background:#000; width: 1200px; margin: 0 auto; height: 45px;}
      .nav a{display: block; width: 200px;float: left; color: #fff; text-decoration: none; text-align: center; line-height: 45px;}
    </style>
  </head>
  <body>
    <div class="banner">
    </div>
    <div class="bignav" id="bignav">
      <div class="nav">
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁</a>
      </div>
    </div>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <p>其他內(nèi)容</p>
    <script type="text/javascript">
      window.onscroll=function(){
        var topScroll =document.body.scrollTop;//滾動(dòng)的距離,距離頂部的距離
        var bignav = document.getElementById("bignav");//獲取到導(dǎo)航欄id
        if(topScroll > 250){ //當(dāng)滾動(dòng)距離大于250px時(shí)執(zhí)行下面的東西
          bignav.style.position = 'fixed';
          bignav.style.top = '0';
          bignav.style.zIndex = '9999';
        }else{//當(dāng)滾動(dòng)距離小于250的時(shí)候執(zhí)行下面的內(nèi)容,也就是讓導(dǎo)航欄恢復(fù)原狀
          bignav.style.position = 'static';
        }
      }
    </script>
  </body>
</html>

以上所述是小編給大家介紹的JS滾動(dòng)到指定位置導(dǎo)航欄固定頂部,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論

高青县| 柘荣县| 禄丰县| 阿坝县| 康保县| 孟津县| 玛沁县| 盖州市| 永德县| 克山县| 资阳市| 嘉善县| 阿拉善左旗| 邳州市| 嘉兴市| 来安县| 建德市| 延安市| 龙门县| 固镇县| 出国| 云霄县| 镇雄县| 台前县| 辽阳县| 济宁市| 军事| 化隆| 通山县| 崇信县| 宿迁市| 大埔县| 石阡县| 汉阴县| 合江县| 自治县| 玛多县| 清新县| 荣成市| 巫山县| 广宁县|