Created
November 11, 2015 14:10
-
-
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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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