Skip to content

Instantly share code, notes, and snippets.

@siriokun
Created July 26, 2013 08:24
Show Gist options
  • Save siriokun/6087199 to your computer and use it in GitHub Desktop.
Save siriokun/6087199 to your computer and use it in GitHub Desktop.
Fixed Navigation on oscon.com/oscon2013
var headerHeight;
// is navigation visible? See #en_header with height 150px, so when scroll down more than 150px, we make the #nav_borders position fixed.
$(function() {
headerHeight = $('#en_header').height() + 1;
$(window).on('scroll', fixNav);
});
// if not visible, then make it fixed
function fixNav() {
if ($(window).scrollTop() >= headerHeight) {
$('#nav_borders').add('#headlining').addClass('fixed');
}
else {
$('#nav_borders').add('#headlining').removeClass('fixed');
}
}
#en_header {
height: 150px;
}
#nav_borders.fixed {
position:fixed;
top:-1px;
_position: absolute; /* ie */
_top: expression(eval(document.body.scrollTop)); /* ie */
z-index: 100;
}
#headlining.fixed {
padding-top: 26px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment