jquery temporary unbinding events

后端 未结 2 954
慢半拍i
慢半拍i 2020-12-31 08:47

maybe I\'m totally missing something about even handling in jQuery, but here\'s my problem.

Let\'s assume there are some event binding, like

$(elemen         


        
2条回答
  •  被撕碎了的回忆
    2020-12-31 09:50

    Another way could be to use custom events, something along these lines:

    var flag = 0;
    $(element).bind("mousemove", function() {
        if(flag) {
            $(this).trigger("supermousemove");
        } else {
            $(this).trigger("magicmousemove");
        }
    }).bind("supermousemove", function() {
        // do something super
    }).bind("magicmousemove", function() {
        // do something magical
    }); 
    
    $("#foo").click(function() {
        flag = flag == 1 ? 0 : 1; // simple switch
    });
    

    Highly annoying demo here: http://jsfiddle.net/SkFvW/

提交回复
热议问题