问题描述
某些支持触摸功能的浏览器(例如Mobile Safari)在<标尺
和旋转
属性中具有 event
对象用于诸如 touchmove
之类的事件。
Some touch-enabled browsers (such as Mobile Safari) have a scale
and rotation
property available on their event
object for events such as touchmove
.
我可以像这样检测对 scale
属性的支持...
I can detect support for the scale
property like so...
document.body.addEventListener("touchmove", function(event) {
var supportsScaleProperty = !!event.scale;
});
但是,有没有一种方法可以检测到它而不必绑定侦听器,然后查找该属性
However, is there a way to detect it without having to bind a listener and then look for the property in the callback?
例如,是否可行?
var supportsScaleProperty = !!(new CustomEvent("TouchEvents")).scale;
我尝试查看,但已弃用。我查看了 new CustomEvent()
,但不确定用于触摸事件的字符串。
I tried looking at createEvent()
, but it's deprecated. I looked at new CustomEvent()
, but wasn't sure which string to use for touch events.
推荐答案
这似乎不可能。 不会告诉我属性是否存在(即使在支持它们的设备上也不存在)。
This doesn't seem to be possible. TJ's solution doesn't tell me if the properties exist (they're never present, even on devices which support them).
所以,似乎我被困住了...
So, it looks like I'm stuck with...
document.body.addEventListener("touchmove", function(event) {
if (event.scale) {
// ...
}
});
这篇关于如何确定浏览器是否支持事件对象的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!