国产探花免费观看_亚洲丰满少妇自慰呻吟_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教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 普宁市| 阳西县| 山西省| 三门县| 余江县| 若尔盖县| 溆浦县| 积石山| 新昌县| 阳东县| 都匀市| 文昌市| 西吉县| 彭阳县| 岑巩县| 桂林市| 金塔县| 苍溪县| 威海市| 信宜市| 平舆县| 班戈县| 金阳县| 柏乡县| 普宁市| 呼图壁县| 东莞市| 呼伦贝尔市| 呼伦贝尔市| 扎兰屯市| 宁明县| 蓝山县| 泰来县| 鄂托克旗| 牟定县| 湘潭市| 金坛市| 健康| 寻乌县| 寻乌县| 轮台县|