Question

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?

Was it helpful?

Solution

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");

OTHER TIPS

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.com/hammerjs/jquery.hammer.js/blob/master/jquery.hammer.js

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top