当我们点击页面的特定部分时,我想更改导航颜色

时间:2018-07-05 13:07:30

标签: jquery css twitter-bootstrap bootstrap-4

我想添加平滑的滚动,并且在滚动时击中特定区域时还要滚动更改导航栏的颜色。下面是我的代码

           <div class="navbar-wrapper">

    <nav class="navbar  navbar-default navbar-fixed-top  navbar-expand-md ">


            <button class="navbar-toggler" type="button" data- 
     toggle="collapse" data-target="#navbarSupportedContent" aria- 
   controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle 
           navigation">
              <span class="navbar-toggle-icon"></span>


            </button>

            <div class="collapse navbar-collapse " 
           id="navbarSupportedContent" >
              <ul class="  navbar-nav  ml-auto"  style="font-size: 14px;font- 
              weight: 700;" >
                <li  class="nav-item ">
                  <a class="nav-link active "   href="#pagetop">HOME <span 
    class="sr-only">(current)</span></a>
                </li>
                <li   class="nav-item">
                  <a class="nav-link smoothScroll"   href="#whatwedo">WHAT WE 
               DO</a>
                </li>
                <li class="nav-item">
                        <a class="nav-link smoothScroll "   
                      href="#contact">CONTACT</a>
                      </li>
                      <li   class="nav-item">
                            <a class="nav-link "  href="#">LOGIN</a>
                          </li>

                </ul>
                </div>
                </nav>
                </div>

我想更改导航栏的颜色

      <section id="whatwedo">

使用scrollspy滚动时,我该如何实现 我正在使用以下CDN链接

            <link rel="stylesheet" 
            href="https://stackpath.bootstrapcdn.com/bootstrap/
             4.1.1/css/bootstrap.min.css" >


             <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" > 
                        </script>
                  <script 
         src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/
                   1.14.3/umd/popper.min.js" ></script>
                  <script src="https://stackpath.bootstrapcdn.com/bootstrap/
                4.1.1/js/bootstrap.min.js" ></script> 

                  <script>
                  $('.navbar-nav .nav-link').click(function(){
                   $('.navbar-nav .nav-link').removeClass('active');
                   $(this).addClass('active');
               })

               </script>

0 个答案:

没有答案