DeviceOrientationEvent
基線 2023 *
新推出
DeviceOrientationEvent 介面是 裝置方向事件 的一部分,它為 Web 開發者提供有關執行網頁的裝置的物理方向的資訊。
建構函式
DeviceOrientationEvent.DeviceOrientationEvent()-
建立一個新的
DeviceOrientationEvent。
例項屬性
DeviceOrientationEvent.absolute只讀-
一個布林值,指示裝置是否正在絕對地提供方向資料。
DeviceOrientationEvent.alpha只讀-
一個數字,表示裝置繞 z 軸的運動,以度為單位,範圍從 0(包含)到 360(不包含)。
DeviceOrientationEvent.beta只讀-
一個數字,表示裝置繞 x 軸的運動,以度為單位,範圍從 -180(包含)到 180(不包含)。這代表裝置的前後運動。
DeviceOrientationEvent.gamma只讀-
一個數字,表示裝置繞 y 軸的運動,以度為單位,範圍從 -90(包含)到 90(不包含)。這代表裝置的左右運動。
DeviceOrientationEvent.webkitCompassHeading非標準 只讀-
一個數字,表示世界座標系下裝置繞 z 軸運動與北方方向之間的差異,以度為單位,範圍從 0 到 360。
DeviceOrientationEvent.webkitCompassAccuracy非標準 只讀-
指南針的精度表示偏差是正的還是負的。通常為 10。
示例
js
window.addEventListener("deviceorientation", (event) => {
console.log(`${event.alpha} : ${event.beta} : ${event.gamma}`);
});
規範
| 規範 |
|---|
| 裝置方向和運動 # deviceorientation |
瀏覽器相容性
載入中…