Skip to content

Instantly share code, notes, and snippets.

@zachakbar
Created April 23, 2020 17:03
Show Gist options
  • Save zachakbar/f96d202036df8c34193090040dc648ea to your computer and use it in GitHub Desktop.
Save zachakbar/f96d202036df8c34193090040dc648ea to your computer and use it in GitHub Desktop.
add/remove classes to header on page scroll
menuIsScrolling: function() {
var $body = $('body'),
$header = $('header[role="banner"]'),
lastScrollTop = 0;
$(window).scroll(function(event){
var st = $(this).scrollTop();
if( st > 0 ) {
$header.addClass( 'is-scrolling' );
}
if ( st > lastScrollTop ){
// downscroll
$header.removeClass( 'is-scrolling-up' );
} else if( st == 0 ) {
// at scrolltop
$header.removeClass( 'is-scrolling is-scrolling-up' );
} else {
// upscroll
$header.addClass( 'is-scrolling-up' );
}
lastScrollTop = st;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment