Home › Forums › JavaScript › issue with sticky navigation › Re: issue with sticky navigation
May 30, 2013 at 1:00 pm
#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’);
}
});
});