Removing hammer events

落花浮王杯 提交于 2019-12-19 03:15:51

问题


I create an event using hammer.js library like this:

Hammer(myElement).on("doubletap", function(evt){
            evt.preventDefault();
        });

How can I then remove the registred event? Can I also use Jquery?


回答1:


It's simply Hammer(myElement).off(eventName);

If you want to use jQuery, then the syntax is:

$(myElement).hammer().on(eventName, callback)

If you want to specify "namespace" for the event, then you declare eg.

$(myElement).hammer().on("tap.namespace", callback);
$(myElement).hammer().on("tap.anotherNamespace", callback2);

which makes it possible to detach only desired event, eg:

$(myElement).hammer().off("tap.anotherNamespace");


来源:https://stackoverflow.com/questions/15427715/removing-hammer-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!