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

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 16:11:21
字體:
來源:轉載
供稿:網友

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

<!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滾動到指定位置導航欄固定頂部,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇宁| 鱼台县| 宁德市| 中方县| 正镶白旗| 龙泉市| 鄂托克旗| 仁化县| 建德市| 新化县| 宜昌市| 天等县| 平南县| 东源县| 民权县| 霍邱县| 上犹县| 大连市| 即墨市| 盱眙县| 洛扎县| 田林县| 久治县| 宁都县| 凤凰县| 贡嘎县| 深水埗区| 东明县| 武定县| 博客| 布尔津县| 定襄县| 英超| 忻城县| 五大连池市| 台南县| 宿迁市| 肥乡县| 铁岭县| 洪泽县| 湄潭县|