Skip to content

Instantly share code, notes, and snippets.

@drocarmo
Last active August 29, 2015 14:00
Show Gist options
  • Save drocarmo/9eed3ad2037ff39db717 to your computer and use it in GitHub Desktop.
Save drocarmo/9eed3ad2037ff39db717 to your computer and use it in GitHub Desktop.
Adds 'sticky' class to HTML nav tag in the DOM
/* Requires latest JQuery lib */
var win = $(window),
nav = $('nav'),
pos = nav.offset().top,
sticky = function(){
if(win.scrollTop() > pos){
nav.addClass('sticky')
} else {
nav.removeClass('sticky')
}
};
win.scroll(sticky)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment