RaV
RaV

Reputation: 1048

Hammer js - off() method doesn't work

I am using Hammer this way, it works (it just triggers next/prev buttons):

var slider = document.getElementsByClassName('slider');

Hammer(slider[0]).on("swiperight", function() {
    prev.click();
});

A according to Stack thread, on event when modal is coming out (hammer is still swiping behind it :/) I am trying to turn it of with:

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

But it doesn't work. It's still swipeing behind modal. Any idea why?

Upvotes: 1

Views: 1749

Answers (1)

Adam Azad
Adam Azad

Reputation: 11297

Save the Hammer instance to a variable. The following example removes 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.github.io/dist/hammer.min.js"></script>

Upvotes: 4

Related Questions