Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One Page Website - Navigation Highlight Current Section

I'm having problems integrating a navigation bar that highlights the current section being viewed on the website. I just want the currently viewed section to be bold in the navigation bar.

Here is the codepen:

HTML

  <nav id="nav-wrap">
    <ul>
      <li class="current"><a class="page" href="#home">Home</a></li>
      <li><a class="page" href="#about">About</a></li>
      <li><a class="page" href="#portfolio">Portfolio</a></li>
      <li><a class="page" href="#scrapbook">Scrapbook</a></li>
      <li><a class="page" href="#contact">Contact</a></li>
    </ul>
  </nav>

  <div class="header-content">
    <img id="logo" src="img/logo.png" alt="logo" height="200px" width="200px">
    <h3>Joseph Cooper</h3>
    <h3>Graphic Designer</h3>
    <p> 10.03.97 </p>
  </div>

<a href="#about"><img id ="down" src="img/down.png" height="42px" width="42px"></a>

like image 908
Vectriixx Avatar asked Mar 26 '26 00:03

Vectriixx


1 Answers

I added two line of code, one to remove bold from all href in navigation, and one to add bold to href that is clicked. Take a look at codepen: http://codepen.io/anon/pen/doaRjy

   function smoothScroll (duration) {
      $('a[href^="#"]').on('click', function(event) {        
          var target = $( $(this).attr('href') );

          $("#nav-wrap a").css('font-weight','normal')/*this line remove bold from all href*/
          $(this).css('font-weight','bold')/*this line add bold to clicked href*/

          if( target.length ) {
              event.preventDefault();
              $('html, body').animate({
                  scrollTop: target.offset().top
              }, duration);
          }
      });
    }
like image 103
Akul Von Itram Avatar answered Mar 27 '26 14:03

Akul Von Itram



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!