Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript issue with sticky navigation Re: issue with sticky navigation

#137080
wolfcry911
Participant

Try this:

$(function () {
var top = $(‘.site-navigation’).offset().top;
$(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();
// whether that’s below the element
if (y >= top) {
// if so, add the fixed class
$(‘.site-navigation’).addClass(‘fixed’);
} else {
// otherwise remove it
$(‘.site-navigation’).removeClass(‘fixed’);
}
});
});