I've successfully implemented a sticky header using jQuery, adding a class to the header when the user scrolls past it. Now, I'm wondering how I can include an additional class to the header when the user is scrolling back up and gets within 50px of the top of the page. This extra class should only be added when the user is scrolling upwards, not downwards, and should be removed once the user reaches the very top of the page.
Here's the code I currently have:
$(window).scroll(function () {
if( $(window).scrollTop() > $('#header').offset().top && !($('#header').hasClass('sticky-header'))){
$('#header').addClass('sticky-header');
} else if ($(window).scrollTop() == 0){
$('#header').removeClass('sticky-header');
}
});