Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have gestures with trackpads?

On a Macbook Pro in Chrome, sliding two fingers across the screen allows you to move backwards and forwards. How do I go about disabling this, and creating custom gestures in jQuery or Javascript?

All I really need to know is how do you detect when two fingers are on the trackpad, which I assume is the best way to do this. You can do it on mobile with e.touches!

like image 555
Johnny Avatar asked Dec 07 '22 10:12

Johnny


2 Answers

Update May 2017

  • Chrome has implemented the new wheel-event. Pinch-Zoom can be detected as a wheel-event with ctrlKey === true.
  • Firefox is going to ship the same behaviour in Fx55.
  • Edge supports the wheel-event unless you are using a "precision-touchpad". No Idea what about pinch-zoom.
  • opera probably matches chrome-behaviour (not tested)
  • safari has basic wheel-events and supports the proprietary (yet kinda great) gestureEvents

Original Answer

As of April 2016, the pinch-zoom gesture is supported in (very) different ways in different browsers:

  • Chrome sends mousewheel-events with ev.ctrlKey===true
  • Mozilla is discussing matching chrome-behaviour: https://bugzilla.mozilla.org/show_bug.cgi?id=1052253
  • In modern Safari (>9.1) gesture-events can be used: https://developer.apple.com/library/archive/releasenotes/General/WhatsNewInSafari/Articles/Safari_9_1.html and https://developer.apple.com/documentation/webkitjs/gestureevent
  • Edge is unlikely to handle it at all.
like image 113
Martin Schuhfuß Avatar answered Dec 28 '22 00:12

Martin Schuhfuß


Touchpads do not trigger touch-related events (but usually control the mouse pointer instead. This cannot be affected by a website for obvious reasons) so that's not possible.

If gestures done on a touchpad have non-standard behaviour this is usually done by the touchpad's driver/software.

like image 43
ThiefMaster Avatar answered Dec 28 '22 00:12

ThiefMaster