You can try this in jQuery like this:
HTML:
<div id="wrapper"> <header> <h1>Floater Navigation</h1> </header> <nav> <p>Navigation Content</p> </nav> <div id="content"> <p>Lorem Ipsum.</p> </div> </div>
CSS:
#wrapper { width:940px; margin: 0 auto; } header { text-align:center; padding:70px 0; } nav { background: #000000; height: 60px; width: 960px; margin-left: -10px; line-height:50px; position: relative; } #content { background: #fff; height: 1500px; box-shadow: 0 0 5px rgba(0,0,0,0.3); } .fixed { position:fixed; }
JQuery:
$(document).ready(function() { // Calculate the height of <header> // Use outerHeight() instead of height() if have padding var aboveHeight = $('header').outerHeight(); // when scroll $(window).scroll(function(){ // if scrolled down more than the headers height if ($(window).scrollTop() > aboveHeight){ // if yes, add "fixed" class to the <nav> // add padding top to the
source: http://www.jay-han.com/2011/11/10/simple-smart-sticky-navigation-bar-with-jquery/
source share