Skip to content

Instantly share code, notes, and snippets.

@sbauch
Created August 4, 2012 22:20
Show Gist options
  • Save sbauch/3260333 to your computer and use it in GitHub Desktop.
Save sbauch/3260333 to your computer and use it in GitHub Desktop.
botostrap navbar sticky
<script> $("section[id]").each(function(idx, el){
var position = $(this).position();
$(this).scrollspy({
min: position.top + 40,
max: position.top + $(this).height(),
onEnter: function(element, position) {
if(console) console.log('entering ' + element.id);
$("div#navbar_to_change").addClass("navbar-fixed-top");
// if ( !primaryNav.hasClass("lock") ) {
// var navLi = $("ul#primary_nav a[href*='#"+element.id+"']").parent();
// navLi.addClass("current").siblings().removeClass("current");
// }
},
onLeave: function(element, position) {
if(console) console.log('leaving ' + element.id);
$("div#navbar_to_change").removeClass("navbar-fixed-top");
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment