DeviceMotionEvent
Experimental: 這是一個實驗中的功能
此功能在某些瀏覽器尚在開發中,請參考兼容表格以得到不同瀏覽器用的前輟。
概要
DeviceMotionEvent
提供了網頁開發者關於裝置位置及旋轉方向改變時的速度資訊。
警告: Currently, Firefox and Chrome does not handle the coordinates the same way. Take care about this while using them.
屬性
DeviceMotionEvent.acceleration
(en-US) Read only-
An object giving the acceleration of the device on the three axis X, Y and Z. Acceleration is expressed in m/s2.
DeviceMotionEvent.accelerationIncludingGravity
(en-US) Read only-
An object giving the acceleration of the device on the three axis X, Y and Z with the effect of gravity. Acceleration is expressed in m/s2.
DeviceMotionEvent.rotationRate
(en-US) Read only-
An object giving the rate of change of the device's orientation on the three orientation axis alpha, beta and gamma. Rotation rate is express in degrees per seconds.
DeviceMotionEvent.interval
(en-US) Read only-
A number representing the interval of time, in milliseconds, at which data is obtained from the device.
範例
window.addEventListener('devicemotion', function(event) {
console.log(event.acceleration.x + ' m/s2');
});
規範
Specification |
---|
DeviceOrientation Event Specification # devicemotion |
瀏覽器相容性
BCD tables only load in the browser