基本信息
源码名称:导航顶部固定效果
源码大小:3.21KB
文件格式:.zip
开发语言:js
更新时间:2020-09-28
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
导航滚动到一定高底后吸顶,锚点定位自动跟随

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title>导航滚动到一定高底后吸顶,锚点定位自动跟随</title>
  <style type="text/css">
  *{margin: 0; padding: 0;}
  .topbox{ height: 500px; background-color: #313131; }
  .section-content{ border-bottom: 5px solid #0000FF; min-height: 500px; background: #eee; width: 1200px; margin: auto; line-height: 500px; text-align: center; }
  .nav-height{ position:relative; height: 50px;}
.nav-wrap { width: 100%;height: 50px;background: #fff;}
.nav-wrap.navFix{position: fixed;top: 0;left: 0;  box-shadow: 0 0 5px rgba(0,0,0, 0.2);border-bottom:1px solid #e3e3e3\9; z-index: 99999;} 
.nav-wrap ul {padding: 0;margin: 0 auto; width: 1200px; display: block; border-bottom: 2px solid #eee;}
.nav-wrap.navFix ul{ border-bottom: 0;}
.nav-wrap li { display: inline-block; text-align: left;height: 50px; line-height: 50px; float: left;}
.nav-wrap li a {display: block;padding: 0 20px;font-size:20px; color: #333; text-decoration: none;}
.nav-wrap li a:hover{color: #4680d1;}
.nav-wrap li a.active {border-bottom:2px solid #4680d1;color: #4680d1;}
.nav-mobile {display: none;font-weight: bold;width: 100%;}
.click-me {width: 150px;height: 30px; background: #4680d1;color: white; text-align: center;line-height: 30px;}
.click-me a {display: block;color: white;}
  </style>
  <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
  <script src='nav.js'></script><!----------文章中提供了JS,请下载使用------------>
 </head>
 <body>
  <div class="topbox">xxxxxxxxxxxxxxxxxxx</div>
  <div class="nav-height" id="navHeight">
    <nav class="nav-wrap" id="nav-wrap">
        <div class="nav-mobile">Click</div>
        <ul class="clearfix">
          <li><a class="active" href="#section1">nav1</a></li>
          <li><a class="" href="#section2">nav2</a></li>
          <li><a class="" href="#section3">nav3</a></li>
          <li><a class="" href="#section4">nav4</a></li>
        </ul>
     </nav>
  </div>
   <div id="section1" class="section-content">
     1
   </div>
   <div id="section2" class="section-content">
     2
   </div>
   <div id="section3" class="section-content">
     3
   </div>
   <div id="section4" class="section-content">
     4
   </div>
   <div style="height: 1000px;background: #f5f5f5;">footer</div>
   <!--内容信息导航吸顶及锚点引入JS-->
  
        <script>
  //内容信息导航吸顶
   $(document).ready(function(){ 
   var navHeight= $("#navHeight").offset().top; 
   var navFix=$("#nav-wrap"); 
   $(window).scroll(function(){ 
    if($(this).scrollTop()>navHeight){ 
     navFix.addClass("navFix"); 
    } 
    else{ 
     navFix.removeClass("navFix"); 
    } 
    }) 
   })
  //内容信息导航锚点
     $('.nav-wrap').navScroll({
        mobileDropdown: true,
        mobileBreakpoint: 768,
        scrollSpy: true
      });
  
      $('.click-me').navScroll({
        navHeight: 0
      });
  
      $('.nav-wrap').on('click', '.nav-mobile', function (e) {
        e.preventDefault();
        $('.nav-wrap ul').slideToggle('fast');
      });
  </script>
 </body>
</html>