[英]How can I detect if the browser supports the gesturestart event?
如何检测浏览器是否支持手势启动和其他手势事件? 这些事件用于捏合旋转和缩放。
它们似乎仅在iOS上可用。
如果它们本身不可用,我希望模仿它们。
尝试此方法,捕获更多设备/浏览器:-
try {
document.createEvent("gesturestart");
alert(true);
}
catch (e) {
alert(false);
}
我认为您可以简单地检查事件是否存在,如下所示:
document.documentElement.ontouchstart !== 'undefined'
您可以通过以下ongesturestart
在window
检查ongesturestart
:
if ('ongesturestart' in window){
// do something
}
此处提到的其他方法在MacOS Safari上将失败。
在MacOS Safari 'ongesturestart' in window
,即使支持手势启动之类的gesturestart
事件'ongesturestart' in window
也会返回false
。
您可以通过检查GestureEvent
来检查手势支持:
'GestureEvent' in window
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.