Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sticky nav bar is flickering when reaching bottom of page

I recently go my nav bar to act as a sticky nav bar that adheres to the top of my page after I scroll down to a certain point, however, when I reach the bottom of my page the entire nav bar flickers, and even disappears sometimes. Think of it as an old TV that would flicker and you would end up hitting on the side to stop the flickering. How would I hit my nav bar to stop it from flickering. Here is my site so you can witness all the glory of the flicker.

Here is my HTML for the nav:

<div id="nav-wrapper">
<div id="nav" class="navbar navbar-inverse affix-top" data-spy="affix">
  <div class="navbar-inner" data-spy="affix-top">
    <div class="container">

      <!-- .btn-navbar is used as the toggle for collapsed navbar content -->
      <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </a>

      <!-- Everything you want hidden at 940px or less, place within here -->
      <div class="nav-collapse collapse">
        <ul class="nav">
            <li><a href="#home">Home</a></li>
            <li><a href="#service-top">Services</a></li>
            <li><a href="#contact-arrow">Contact</a></li>
        </ul><!--/.nav-->
      </div><!--/.nav-collapse collapse pull-right-->
    </div><!--/.container-->
  </div><!--/.navbar-inner-->
</div><!--/#nav /.navbar navbar-inverse-->
</div><!--/#nav-wrapper-->

And here is my JS:

<script>
    $(document).ready(function() {
        $('#nav-wrapper').height($("#nav").height());
        $('#nav').affix({
            offset: 675
        });
    });
</script>

An important note should be that this only began occurring after I changed the offset in my JS from offset: $('#nav').position() to offset: 675. You might say, well just change it back, but with the old offset, my sticky nav would jump prematurely to the top.

Thanks for any help of input you can provide me!

like image 408
Brian Avatar asked Feb 12 '13 12:02

Brian


People also ask

Why is my navbar moving?

This behaviour is happening because position:fixed element is out of the normal document flow so it's not taking the width of its container div ( navbar-wrapper ). You need to calculate that width on the sticky element explicitly.

How do I make my navbar sticky when scrolling?

To create a sticky navbar, you use the position: fixed; CSS property to "stick" your navbar to the viewport, and position: sticky; to make it stick to its parent element.

What is a sticky top navigation bar?

Sticky navs are navigation components that stick to the top of the page as you scroll down. For a long time, making the nav “stick” required using JavaScript to detect when the navigation was going to scroll past the top of the page, then adding a class to switch to position: absolute .


2 Answers

Answer from this Bootstrap 3 Fixed Top Navbar...

Just add the following to .navbar

.navbar
{
   -webkit-backface-visibility: hidden;
}
like image 176
ken Avatar answered Oct 12 '22 11:10

ken


Just add this to your CSS class.

.navbar-fixed-top, .navbar-fixed-bottom { position:unset; }
like image 23
Rajon Tanducar Avatar answered Oct 12 '22 13:10

Rajon Tanducar