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

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 15:15:00
字體:
來源:轉載
供稿:網友

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

<!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>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 松潘县| 宜都市| 麻城市| 确山县| 南开区| 石嘴山市| 宜章县| 准格尔旗| 虞城县| 黎平县| 东乌珠穆沁旗| 林芝县| 连州市| 特克斯县| 临猗县| 营口市| 濉溪县| 和顺县| 讷河市| 荆州市| 黔西县| 新干县| 东兰县| 义乌市| 筠连县| 丹棱县| 白水县| 梅河口市| 德江县| 南投市| 河东区| 丹寨县| 漠河县| 苗栗市| 资中县| 甘孜| 东港市| 茶陵县| 平利县| 广宗县| 嘉定区|