简体   繁体   中英

How can I detect if the browser supports the gesturestart event?

How can I detect if the browser supports the gesturestart and other gesture events? These events are used for pinch to rotate and zoom.

They seem to be only available on iOS.

I wish to emulate them if they are not available natively.

Try this method, catches more devices/browsers :-

try {
  document.createEvent("gesturestart");
  alert(true);
}
catch (e) {
  alert(false);
}

我认为您可以简单地检查事件是否存在,如下所示:

document.documentElement.ontouchstart !== 'undefined'

You can check for ongesturestart in window as:

if ('ongesturestart' in window){

  // do something 
}

Other methods mentioned here will fail on MacOS Safari.

In MacOS Safari, 'ongesturestart' in window returns false , even though gesture events like gesturestart are supported.

You can check for gesture support by checking for GestureEvent :

'GestureEvent' in window

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM