Skip to content

Instantly share code, notes, and snippets.

@overwine
Last active August 29, 2015 14:26
Show Gist options
  • Save overwine/d5cf59ab2a907b9cebde to your computer and use it in GitHub Desktop.
Save overwine/d5cf59ab2a907b9cebde to your computer and use it in GitHub Desktop.
Scroll up and scroll down detection + animation
var lastScrollTop;
//console.log(lastScrollTop);
$(window).scroll(function(event){
$('.top-filter').stop();
var currentScrollTop = $(window).scrollTop();
if (currentScrollTop > lastScrollTop){
$('.top-filter').animate({
top: "-20px",
}, 1000);
console.log("Scroll down!");
//$('body').addClass('has-scrolled')
} else {
$('.top-filter').animate({
top: "147px",
}, 1000);
console.log("Scroll up!");
//$('body').removeClass('has-scrolled')
}
console.log(lastScrollTop);
console.log(currentScrollTop);
lastScrollTop = currentScrollTop;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment