Skip to content

Instantly share code, notes, and snippets.

@digitup
Created November 3, 2012 19:35
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 digitup/4008424 to your computer and use it in GitHub Desktop.
Save digitup/4008424 to your computer and use it in GitHub Desktop.
jQuery - Fixed menu after scrolling
$(window).scroll(function () {
if (!docked && (menu.offsetTop - scrollTop() < 0)) {
menu.style.top = 0;
menu.style.position = 'fixed';
menu.className = 'docked';
docked = true;
} else if (docked && scrollTop() <= init) {
menu.style.position = 'absolute';
menu.style.top = init + 'px';
menu.className = menu.className.replace('docked', '');
docked = false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment