I'm trying to wrap this code:
if($(window).width() > 980) {
$(window).on("scroll", function() {
if($(window).scrollTop() > 20) {
//add black background
$(".x-navbar").addClass("active");
$(".x-navbar .desktop .x-nav li a").addClass("small-bar");
}
else {
//remove background
$(".x-navbar").removeClass("active");
$(".x-navbar .desktop .x-nav li a").removeClass("small-bar");
}
});
}
in a function, so that I can disable it under 980px width.
The thing I'm trying to achive is something like this:
create a function as here under:
navBar = function () {
// the whole code goes here.
}
and then "disable" it in the mobile under 980px width like this:
if($(window).width() < 980) {
// DON'T run the funcion called "navBar".
}
The problem I'm having is that if the window gets resized to a width under 980px the code above will not listen to the resize and it will run anyway.