0

Here is my code:

<div id="nav" class="ten columns">
<ul class="navb">
<li <?php if ($page == "#about"){ echo "class='active'";} ?> ><a href="#aboutintro">About</a></li>
<li <?php if ($page == "#portfolio"){ echo "class='active'";} ?> ><a href="#portintro">Portfolio</a></li>
<li <?php if ($page == "#content"){ echo "class='active'";} ?> ><a href="#contactintro">Contact</a></li>
<li <?php if ($page == "#home"){ echo "class='active'";} ?> ><a href="#homeintro">Home</a></li>
</ul>
</div>

When i scroll down, i want the navbar at the top to stay fixed at teh top of the page. Here is my css i have up to now on the nav bar:

ul.navb li.active {
border-bottom: 2px solid #9EADFF;
}

2 Answers2

0

Try this i placed the example script there may be u need this Demo Here

$(document).ready(function () {

    var menu = $('.menu');
    var origOffsetY = menu.offset().top;

    function scroll() {
        if ($(window).scrollTop() >= origOffsetY) {
            $('.menu').addClass('sticky');
            $('.content').addClass('menu-padding');
        } else {
            $('.menu').removeClass('sticky');
            $('.content').removeClass('menu-padding');
        }


    }

    document.onscroll = scroll;

});
I'm Geeker
  • 4,601
  • 5
  • 22
  • 41
0

If you don't have special requirements this is sufficient:

#nav{
    position:fixed;
    top:0;
}
Alberto
  • 1,853
  • 1
  • 18
  • 22