-
-
Save jordanthomas/8c307000495bea01e942 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 = $(window).scrollTop(); | |
$(window).scroll(function(event){ | |
var currentScrollTop = $(window).scrollTop(); | |
var scrollingUp = currentScrollTop > lastScrollTop; | |
var $filter = $('.top-filter'); | |
if (scrollingUp) { | |
animating = true; | |
if ($filter.css('top') !== "-20px") { | |
$filter.filter(':not(:animated)').animate({ | |
top: "-20px", | |
}, 1000); | |
} | |
console.log("Scroll down!"); | |
} else { | |
if ($filter.css('top') !== "147px") { | |
$filter.filter(':not(:animated)').animate({ | |
top: "147px", | |
}, 1000); | |
} | |
console.log("Scroll up!"); | |
} | |
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