Skip to content

Instantly share code, notes, and snippets.

@sivagao
Created January 11, 2014 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivagao/8373112 to your computer and use it in GitHub Desktop.
Save sivagao/8373112 to your computer and use it in GitHub Desktop.
scroll to fix navbar
$(document).ready(function() {
var navpos = $('#mainnav').offset();
console.log(navpos.top);
$(window).bind('scroll', function() {
if ($(window).scrollTop() > navpos.top) {
$('#mainnav').addClass('fixed');
}
else {
$('#mainnav').removeClass('fixed');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment