I'm creating a 1 page website, I want to remove a class when the user scrolls down and add the class when the user scrolls up.
I've got this working to a point but it's not correct, at the moment when the user scrolls down 50px from the top then the class is removed and it's added when the user scrolls up 50px from the top.
I want it so that they can be almost at the bottom of the page and if the scroll up the class is there and if they scroll down then it's removed
Here's the query I have so far
jQuery(document).ready(function($) {
$(".test").addClass("mobile");
$(window).scroll(function(){
var scroll = $(window).scrollTop();
if (scroll >= 50) {
$(".test").removeClass("mobile");
} else if (scroll <= 50) {
$(".test").addClass("mobile");
}
});
});