判断鼠标滚动方向 - 很好的思路

scroll(function(direction) { console.log(direction) });    
function scroll( fn ) {
    var beforeScrollTop = document.body.scrollTop,
        fn = fn || function() {};
    window.addEventListener("scroll", function() {
        var afterScrollTop = document.body.scrollTop,
            delta = afterScrollTop - beforeScrollTop;
        if( delta === 0 ) return false;
        fn( delta > 0 ? "down" : "up" );
        beforeScrollTop = afterScrollTop;
    }, false);
}
posted @ 2016-03-15 13:13  小数  阅读(...)  评论(...编辑  收藏