Javascript
jQuery(function(){
jQuery(window).scroll(function() {
var windowWidth = jQuery(window).width();
//set window width you want menu to change sticky position
if(windowWidth > 768) {
//scroll distance down page you want sticky nav to enable (larger than windowWidth set above)
if (jQuery(this).scrollTop() >= 190) {
jQuery('.NAV_CLASS’).addClass('sticky-nav');
}
else {
jQuery('.NAV_CLASS').removeClass('sticky-nav');
}
} else {
//scroll distance down you want sticky nav to enable (smaller than windowWidth set above)
if (jQuery(this).scrollTop() >= 300) {
jQuery('.NAV_CLASS').addClass('sticky-nav');
}
else {
jQuery('.NAV_CLASS').removeClass('sticky-nav');
}
}
});
});
</script>
** .NAV_CLASS = existing class on menu
CSS
position: fixed;
}
** extra styling may be necessary on sticky-nav
Leave a Reply