Removing hammer events

后端 未结 2 990
既然无缘
既然无缘 2021-01-05 20:57

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

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


        
相关标签:
2条回答
  • 2021-01-05 21:28

    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

    0 讨论(0)
  • 2021-01-05 21:39

    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");
    
    0 讨论(0)
提交回复
热议问题