判断滚轮滚动方向

// 判断鼠标滚动方向
function wheelDirection(fn) {
    var beforeScrollTop = $(window).scrollTop();
    var fn = fn || function(){};
    $(window).on('scroll',function(){
        var afterScrollTop = $(window).scrollTop();
        var direction = afterScrollTop - beforeScrollTop;
        if( direction === 0 ) return false;
        fn( direction > 0 ? "down" : "up" );
        beforeScrollTop = afterScrollTop;
    })
}

 

posted @ 2017-02-27 10:58  无情码字员  阅读(291)  评论(0编辑  收藏  举报