jQuery判断页面滚动条滚动方向

代码2017-11-201,204 人已阅来源:网络

jQuery判断页面滚动条滚动方向

var before = $(window).scrollTop();
$(window).scroll(function () {
    var after = $(window).scrollTop();
    if (before < after) {
        console.log('上');
        before = after;
    };
    if (before > after) {
        console.log('下');
        before = after;
    };
});