ngryman / jquery.finger

:v: jQuery touch & gestures, fingers in the nose.
https://ngryman.sh/jquery.finger/
MIT License
423 stars 66 forks source link

Gracefully handle multi-touch events #54

Open CedricReichenbach opened 7 years ago

CedricReichenbach commented 7 years ago

Currently, it's implicitly assumed there's only a maximum of one touch active at any time, leading to unexpected behaviour when e.g. tapping with a second finger while dragging (drag is cancelled, but end event never fired).

The most simple workaround would be to simply ignore any additional touches and prevent them from interfering with the current state. This would be quite straightforward with two guards, in the start and stop handlers respectively:

Top of startHandler, after left/right mouse button test:

// ignore additional touches
if (hasTouch && event.originalEvent.touches.length > 1)
    return;

Top of stopHandler, after clearing timeout:

// ignore lifting of additional touches (multitouch)
if (hasTouch && event.originalEvent.touches.length > 0)
    return;
ngryman commented 7 years ago

Thanks for the proposal 👍 Would you mind opening a PR for this?