Skip to content

Instantly share code, notes, and snippets.

@avtarnanrey
Created November 26, 2016 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avtarnanrey/76d1560381797bd98f4ab60f35bdbb46 to your computer and use it in GitHub Desktop.
Save avtarnanrey/76d1560381797bd98f4ab60f35bdbb46 to your computer and use it in GitHub Desktop.
Hide / Show button on Scroll Function
var position, direction, previous;
$(window).scroll(function(){
if( $(this).scrollTop() >= position ){
direction = 'down';
if(direction != previous){
$('.menu-toggle').addClass('hide');
previous = direction;
}
} else {
direction = 'up';
if(direction !== previous){
$('.menu-toggle').removeClass('hide');
previous = direction;
}
}
position = $(this).scrollTop();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment