Skip to content

Instantly share code, notes, and snippets.

@juanbrujo
Created March 20, 2017 14:33
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 juanbrujo/0a2e9c82eacffa845c8d570ec667db57 to your computer and use it in GitHub Desktop.
Save juanbrujo/0a2e9c82eacffa845c8d570ec667db57 to your computer and use it in GitHub Desktop.
addClass2Menu: Add class to menu if certain height is reached
/**
* Add class to menu if certain height is reached
*/
function addClass2Menu(container, classname, height){
$(window).on('load scroll', function(){
var scroll = $(window).scrollTop();
if( scroll >= height) {
container.addClass(classname);
} else {
container.removeClass(classname);
}
});
}
// Use:
addClass2Menu( $('.menu-top'), 'sticky', '100' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment