I have some code which adds a class at a certain page scroll point, which I need for a particular scenario however I do not need this on mobile.
$(window).scroll(function() {
if ($(".navbar").offset().top > 500) {
$(".navbar-fixed-top").addClass("top-nav-collapse");
} else {
$(".navbar-fixed-top").removeClass("top-nav-collapse");
}
});
Could I combine this with something like...
function checkWidth() {
if ($(window).width() < 514) {
$('#menu2').addClass('f-nav');
} else {
$('#menu2').removeClass('f-nav');
}
}
$(window).resize(checkWidth);
To say switch the classes but only if the width is above say 480px?
I appreciate this is probably newbie but I wondered if the window scroll function could just be part of the if condition?