国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > JS > 正文

JS滾動到指定位置導航欄固定頂部

2024-05-06 16:38:14
字體:
來源:轉載
供稿:網友

最近整理一下之前做的一個項目,把滾動條動態固定頂部的代碼整理出來和大家分享,上代碼

<!DOCTYPE html><html>  <head>    <meta charset="UTF-8">    <title>js滾動到指定位置導航欄固定頂部</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>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <p>其他內容</p>    <script type="text/javascript">      window.onscroll=function(){        var topScroll =document.body.scrollTop;//滾動的距離,距離頂部的距離        var bignav = document.getElementById("bignav");//獲取到導航欄id        if(topScroll > 250){ //當滾動距離大于250px時執行下面的東西          bignav.style.position = 'fixed';          bignav.style.top = '0';          bignav.style.zIndex = '9999';        }else{//當滾動距離小于250的時候執行下面的內容,也就是讓導航欄恢復原狀          bignav.style.position = 'static';        }      }    </script>  </body></html>

以上所述是小編給大家介紹的JS滾動到指定位置導航欄固定頂部,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VeVb武林網網站的支持!


注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 融水| 南华县| 襄汾县| 光泽县| 巴彦淖尔市| 枣阳市| 南昌县| 固安县| 宣威市| 乾安县| 博爱县| 稷山县| 竹溪县| 乌拉特前旗| 梁平县| 新余市| 油尖旺区| 界首市| 诸城市| 昭平县| 绥化市| 长葛市| 临猗县| 伊金霍洛旗| 堆龙德庆县| 绥棱县| 商水县| 大兴区| 尼玛县| 巩留县| 商都县| 颍上县| 明光市| 孝昌县| 老河口市| 滕州市| 涞源县| 沾化县| 克东县| 会理县| 衡水市|