Is it possible to have gestures with trackpads?

烂漫一生 提交于 2020-01-04 04:43:26

问题


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!


回答1:


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.




回答2:


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.


来源:https://stackoverflow.com/questions/14086337/is-it-possible-to-have-gestures-with-trackpads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!