最新国产好看的视频,伊人天堂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)固定頂部的代碼整理出來(lái)和大家分享

最近整理一下之前做的一個(gè)項(xiàng)目,把滾動(dòng)條動(dòng)態(tài)固定頂部的代碼整理出來(lá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" >首頁(yè)</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁(yè)</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁(yè)</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁(yè)</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁(yè)</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁(yè)</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)航欄固定頂部,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論

科尔| 宁阳县| 新安县| 腾冲县| 蕉岭县| 体育| 巍山| 昌平区| 莎车县| 中西区| 贵溪市| 汉沽区| 红河县| 资中县| 修水县| 平乡县| 昌吉市| 星子县| 博湖县| 涟源市| 行唐县| 镇康县| 罗田县| 赣州市| 叶城县| 睢宁县| 晴隆县| 阜宁县| 清远市| 苏州市| 红安县| 墨竹工卡县| 明水县| 茶陵县| 临猗县| 兴安县| 太谷县| 宁国市| 通山县| 长寿区| 策勒县|