Skip to content

Instantly share code, notes, and snippets.

@kpry
Last active May 31, 2020 22:41
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 kpry/01dd51b532e0d9a15e428946d53820fe to your computer and use it in GitHub Desktop.
Save kpry/01dd51b532e0d9a15e428946d53820fe to your computer and use it in GitHub Desktop.
Sticky Navigation Header Using jQuery
jQuery(document).ready(function(){
var $window = jQuery(window),
$mainMenuBar = jQuery('#nav-module'),
$mainMenuAnchor = jQuery('#anchor-stick');
$window.scroll(function(){
var window_top = $window.scrollTop();
var div_top = $mainMenuAnchor.offset().top;
if (window_top > div_top){
$mainMenuBar.addClass('sticky');
} else {
$mainMenuBar.removeClass('sticky');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment