MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/MDN-dev-survey

翻譯不完整。請協助 翻譯此英文文件

這是一個實驗中的功能
此功能在某些瀏覽器尚在開發中,請參考兼容表格以得到不同瀏覽器用的前輟。

概要

DeviceMotionEvent 提供了網頁開發者關於裝置位置及旋轉方向改變時的速度資訊。

Warning: Currently, Firefox and Chrome does not handle the coordinates the same way. Take care about this while using them.

屬性

DeviceMotionEvent.acceleration 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 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 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 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 Status Comment
Device Orientation Events Working Draft Initial specification.

瀏覽器相容性

  
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) (Yes) 6 (6) ? ? ?
  
Feature Android Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support (Yes) (Yes) 6.0 (6) No support No support 4.2

參見

文件標籤與貢獻者

 此頁面的貢獻者: jackblackevo
 最近更新: jackblackevo,