[英]How to determine if browser supports properties on event object?
一些啟用觸摸功能的瀏覽器(例如Mobile Safari)在其event
對象上具有諸如touchmove
類的scale
和rotation
屬性。
我可以像這樣檢測到對scale
屬性的支持...
document.body.addEventListener("touchmove", function(event) {
var supportsScaleProperty = !!event.scale;
});
但是,有沒有一種方法可以檢測到它而不必綁定偵聽器,然后在回調中查找屬性?
例如,這是否有效?
var supportsScaleProperty = !!(new CustomEvent("TouchEvents")).scale;
我嘗試查看createEvent()
,但已棄用。 我查看了new CustomEvent()
,但不確定用於觸摸事件的字符串。
您可能可以使用Event
構造函數 :
if ('scale' in new Event("touchmove")) {
// It has it
}
這似乎不可能。 TJ的解決方案不會告訴我這些屬性是否存在(即使在支持它們的設備上也不存在)。
所以,看起來我很固執...
document.body.addEventListener("touchmove", function(event) {
if (event.scale) {
// ...
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.