有没有办法暂停在JQuery中捕获事件?

时间:2015-11-27 14:23:31

标签: jquery

例如,我想捕获一个'scroll'事件,然后暂停侦听,直到执行处理程序。我已经尝试解决这个问题几个小时已经没有成功。

$('body').bind('wheel', function(e){
    e.stopPropagation();
    if(e.originalEvent.wheelDelta /120 > 0) {
        console.log("up");
    }
    else{
        console.log("down");
    }
});

编辑:添加了代码示例。

1 个答案:

答案 0 :(得分:0)

您可以在body上切换课程:

$('body').addClass('wheel_disabled'); //removeClass('wheel_disabled');

委派你的活动:

$(document).bind('wheel', 'body:not(.wheel_disabled)', function (e) {
    if (e.originalEvent.wheelDelta / 120 > 0) {
        console.log("up");
    } else {
        console.log("down");
    }
});
相关问题