document.addEventListener("scroll", myFunction);
var lastScrolled = 1;
function myFunction() {
var scrolled = window.pageYOffset || document.documentElement.scrollTop;
if (scrolled < lastScrolled) {
alert("TOP");
} else {
alert("BOTTOM");
}
lastScrolled = scrolled;
}