Skip to content

Instantly share code, notes, and snippets.

@MagneticMule
Created October 6, 2017 17: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 MagneticMule/37492e6ee20715669c21783da8479ed9 to your computer and use it in GitHub Desktop.
Save MagneticMule/37492e6ee20715669c21783da8479ed9 to your computer and use it in GitHub Desktop.
/**
* menu-scroll.js
*
* "Locks" the menu div when it reaches the top of the page. Relies on the class .fixed to the menu bar div
*.fixed {
* position: fixed
* top: 0;
* left: 0;
*}
*/
jQuery(window).scroll(function() {
var scrollTop = jQuery(this).scrollTop();
var topMenu = jQuery("#top-menu");
var pageHeader = jQuery("body").find("#masthead");
if (scrollTop >= pageHeader.height()) {
jQuery(topMenu).addClass("fixed");
} else {
jQuery(topMenu).removeClass("fixed");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment