I have the following jQuery which applies a class to my fixed header to shrink it when the user is scrolled any distance down the page:
$(window).scroll(function() {
if ($(this).scrollTop() > 1){
$('div.single-level-nav').addClass("shrunk");
}
else{
$('div.single-level-nav').removeClass("shrunk");
}
});
This is working, but of course is constantly firing whenever the user is scrolling. This seems a bit of overkill, and not a great use of resources.
What I have may be the best way of achieving what I want, but I was wondering if there was a better way.
if (window.scrollY > 1)
. BTW there'stoggleClass
in jQuery. \$\endgroup\$