//判断是上滚还是下滚
function scroll(fn) {
var beforeScrollTop = document.documentElement.scrollTop || document.body.scrollTop,
fn = fn || function () {
};
window.addEventListener("scroll", function () {
var afterScrollTop = document.documentElement.scrollTop || document.body.scrollTop,
delta = afterScrollTop - beforeScrollTop;
if (delta === 0) return false;
fn(delta > 0 ? "down" : "up");
beforeScrollTop = afterScrollTop;
}, false);
}
scroll(function (direction) { console.log(direction) })