Skip to content

Instantly share code, notes, and snippets.

@jordanthomas
Forked from overwine/newbs.js
Created August 6, 2015 20:19
Show Gist options
  • Save jordanthomas/8c307000495bea01e942 to your computer and use it in GitHub Desktop.
Save jordanthomas/8c307000495bea01e942 to your computer and use it in GitHub Desktop.
Scroll up and scroll down detection + animation
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