jquery 判断滚动条上下滚动

$(window).scroll(function() {
    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;
        };
    });
});

jquery js判断鼠标滚轮 上下滚动

$('#contain2').on("mousewheel DOMMouseScroll", function(e) {
    var delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? 1 : -1)) || (e.originalEvent.detail && (e.originalEvent.detail > 0 ? -1 : 1));
    if (delta > 0) {
        console.log("wheelup")
    } else if (delta < 0) {
        console.log("wheeldown")
    }
})

 

发表评论

邮箱地址不会被公开。 必填项已用*标注