Hammer js-off () method not working

I use Hammer this way, it works (it just launches the next / prev buttons):

var slider = document.getElementsByClassName('slider'); Hammer(slider[0]).on("swiperight", function() { prev.click(); }); 

A according to the Stack thread , on the event that the modal exits (the hammer is still holding on to it: /) I'm trying to rotate it with:

 Hammer(slider[0]).off("swipeleft"); Hammer(slider[0]).off("swiperight"); 

But that will not work. He is still holding on to the modal. Any idea why?

+1
source share
1 answer

Save Hammer instance to variable. It works that way. The following example will remove the pan event after 5 seconds.

 var h = new Hammer(document); h.on('pan', function(){ console.log('Panned'); }); setTimeout(function(){ console.log('removed'); h.off('pan'); }, 5000); 
 <script src="http://hammerjs.imtqy.com/dist/hammer.min.js"></script> 
+3
source

Source: https://habr.com/ru/post/1469444/


All Articles