jquery-archive / jquery-mobile

jQuery Mobile Framework
https://jquerymobile.com
Other
9.7k stars 2.41k forks source link

swipeleft and swiperight events fire when pinch-zooming #8658

Open teo1978 opened 4 years ago

teo1978 commented 4 years ago

Example code:

$(document).on("swipeleft", function(e) {
    console.log("Swipe left detected");
});
$(document).on("swiperight", function(e) {
    console.log("Swipe right detected");
});

And the viewport metatag in the html:

<meta name="viewport" content="width=device-width, initial-scale=1">

Steps to reproduce:

  1. On a real mobile device, pinch-zoom

Expected: shouldn't ever trigger a swipe left or right event, because you are using TWO fingers. That makes it obvious that it is not a swipe gesture

Observed: sometimes randomly triggers a swipe event while you are pinch-zooming.

I'm under the impression that you're just testing for a touch event doing a drag motion of a length and/or speed above a certain threshold, regardless of whether there are other touch points at the same time.

Instead, you should add the condition that the finger touching and dragging is the only finger present.