Reputation: 11404
I am running into issues with getting Hammer.js (with the jQuery plugin) to function properly when using swiperight
. Therefore, I need to use panright
.
When panning to the right, my event fires many, many times.
How can this be updated so it only runs once? (then again when the user swipes to the right or left on another slide)
$('.slide').hammer().on('panright', doSomething);
Upvotes: 5
Views: 2887
Reputation: 139
You can filter the event by isFinal property:
var mc = new Hammer($('.screen'));
mc.on("swipeleft", moveHandler);
mc.on("swiperight", moveHandler);
function moveHandler(event){
if(event.isFinal){
// do something on the last animation frame
}
}
Upvotes: 2
Reputation: 324
There are other events called 'swipeleft' and 'swiperight'. This will respond to 1 swipe event instead of pan's multiple fired events.
var mc = new Hammer($('.screen'));
mc.on("swipeleft", moveHandler);
mc.on("swiperight", moveHandler);
function moveHandler(event){
// do something
}
Upvotes: 1
Reputation: 532
I think you should capture a panend event. For example:
var myElement = document.getElementById('myID');
var mc = new Hammer.Manager(myElement);
mc.add(new Hammer.Pan({direction:Hammer.DIRECTION_HORIZONTAL, threshold:80, pointers: 0}));
mc.on("panend", function(ev) {
if(ev.direction == Hammer.DIRECTION_RIGHT)
{
//do what you want here
}
});
Upvotes: 9