欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2017年07月03日 15:48:36   作者:一個奕  
最近整理一下之前做的一個項目,把滾動條動態(tài)固定頂部的代碼整理出來和大家分享

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

<!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時執(zhí)行下面的東西
          bignav.style.position = 'fixed';
          bignav.style.top = '0';
          bignav.style.zIndex = '9999';
        }else{//當滾動距離小于250的時候執(zhí)行下面的內容,也就是讓導航欄恢復原狀
          bignav.style.position = 'static';
        }
      }
    </script>
  </body>
</html>

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

相關文章

  • security.js實現的RSA加密功能示例

    security.js實現的RSA加密功能示例

    這篇文章主要介紹了security.js實現的RSA加密功能,結合實例形式分析了基于security.js進行RSA加密的相關操作技巧,需要的朋友可以參考下
    2018-06-06
  • EasyUi中的Combogrid 實現分頁和動態(tài)搜索遠程數據

    EasyUi中的Combogrid 實現分頁和動態(tài)搜索遠程數據

    jquery easyui中的combogrid比較特殊,算是combo和grid的組合,combogrid結合一個可編輯的文本框和下拉數據網格面板,可以讓用戶迅速找到并選擇,又可以進行搜索,展示與當前輸入的字符相匹配的數據。下面給大家介紹EasyUi中的Combogrid 實現分頁和動態(tài)搜索遠程數據
    2016-04-04
  • jQuery實現手風琴特效

    jQuery實現手風琴特效

    這篇文章主要為大家詳細介紹了前端js實現手風琴效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-01-01
  • 最全面的JS倒計時代碼

    最全面的JS倒計時代碼

    這篇文章主要為大家詳細介紹了最全面的JS倒計時代碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • js FLASH幻燈片字符串中有連接符&的處理方法

    js FLASH幻燈片字符串中有連接符&的處理方法

    一般情況下我們在FLASH幻燈片字符串中有連接符時點擊鏈接就會不正常,造成鏈接中的參數丟失,那么就需要用encodeURIComponent來對鏈接地址進行編碼
    2012-03-03
  • 自己封裝的一個原生JS拖動方法(推薦)

    自己封裝的一個原生JS拖動方法(推薦)

    下面小編就為大家?guī)硪黄约悍庋b的一個原生JS拖動方法(推薦)。小編覺得挺不錯的,希望對大家有所幫助。一起跟隨小編過來看看吧,祝大家游戲愉快哦
    2016-11-11
  • 分享JS數組求和與求最大值的方法

    分享JS數組求和與求最大值的方法

    數組求和在項目需求中還是挺常見的,比如購物車金額統(tǒng)計、人員的前臺統(tǒng)計等等。今天小編先是給大家分享了JS數組求和的兩個方法,而后又用實例演示js數組求和,并求出數組中的最大值,一起來看看吧。
    2016-08-08
  • JavaScript實現的商品搶購倒計時功能示例

    JavaScript實現的商品搶購倒計時功能示例

    這篇文章主要介紹了JavaScript實現的商品搶購倒計時功能,可實現分秒級別的實時顯示倒計時效果,涉及js日期時間計算與頁面元素動態(tài)操作相關技巧,需要的朋友可以參考下
    2017-04-04
  • js實現數組轉樹示例

    js實現數組轉樹示例

    這篇文章主要為大家介紹了js實現數組轉樹示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-06-06
  • JavaScript中break、continue和return的用法區(qū)別實例分析

    JavaScript中break、continue和return的用法區(qū)別實例分析

    這篇文章主要介紹了JavaScript中break、continue和return的用法區(qū)別,結合實例形式詳細對比分析了JavaScript中break、continue和return的基本功能、使用方法、區(qū)別與操作注意事項,需要的朋友可以參考下
    2020-03-03

最新評論