Last active
August 29, 2015 14:26
-
-
Save overwine/d5cf59ab2a907b9cebde to your computer and use it in GitHub Desktop.
Scroll up and scroll down detection + animation
This file contains 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
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