Skip to content

Instantly share code, notes, and snippets.

@jefferson
Created November 11, 2015 14:10
Show Gist options
  • Save jefferson/dba1e802cb3ed88081e8 to your computer and use it in GitHub Desktop.
Save jefferson/dba1e802cb3ed88081e8 to your computer and use it in GitHub Desktop.
The scroll movement is smooth and animated as expected, I just wish there was a better way to track it; without making a million events at every pixel. How can I prevent this?
// show hide subnav depending on scroll direction
//original post: https://jsfiddle.net/ZzaichikK/MUvsG/
var position = $(window).scrollTop();
$(window).scroll(function () {
var scroll = $(window).scrollTop();
if (scroll > position) {
//only piece that matters
$('div.navbar.navbar-fixed-top')
.stop(true, false)
.animate({
'opacity': 0
}, 'fast');
// scrolling downwards, only here for dev purposes
console.log('moving DOWN the page');
} else {
//only piece that matters
$('div.navbar.navbar-fixed-top')
.stop(true, false)
.animate({
'opacity': 1
}, 'fast');
// scrolling upwards
console.log('moving UP the page');
}
position = scroll;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment