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?
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?
Share Improve this question asked Mar 15, 2013 at 8:26 JacobJacob 4,03123 gold badges91 silver badges151 bronze badges 1-
2
I have no experience of Hammer, but since the syntax looks very similar to jQuery, maybe Hammer uses
.off()
just like jQuery does? That is just a wild guess though. – Christofer Eliasson Commented Mar 15, 2013 at 8:29
2 Answers
Reset to default 16It'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");
In the documentation of hammer.js API, it is stated that it will not remove the dom events, using $(element).off() will not resolve your issues, a work around is to use the hammer.js jquery wrapper, their events are registered on an element using the bind function. Use the unbind to remove all or specific events.
$(element).hammer().unbind();
$(element).hammer().bind('swipeleft', 'swiperight', function(){});
The wrapper is here: https://github./hammerjs/jquery.hammer.js/blob/master/jquery.hammer.js