DeviceMotionEvent

这是 实验性技术
检查 浏览器兼容性表格 在生产中使用这之前。

DeviceMotionEvent provides web developers with information about the speed of changes for the device's position and orientation.

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

构造函数

DeviceMotionEvent.DeviceMotionEvent()
创建新的 DeviceMotionEvent .

特性

DeviceMotionEvent.acceleration 只读
An object giving the acceleration of the device on the three axis X, Y and Z. Acceleration is expressed in m/s 2 .
DeviceMotionEvent.accelerationIncludingGravity 只读
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/s 2 .
DeviceMotionEvent.rotationRate 只读
An object giving the rate of change of the device's orientation on the three orientation axis alpha, beta and gamma. Rotation rate is expressed in degrees per seconds.
DeviceMotionEvent.interval 只读
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');
});
					

规范

规范 状态 Comment
DeviceOrientation Event Specification
The definition of 'DeviceMotionEvent' in that specification.
编者草案 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
DeviceMotionEvent
Chrome 11 Edge ≤18 Firefox 6 IE No Opera 15 Safari 5 WebView Android ≤37 Chrome Android 18 Firefox Android 6 Opera Android 14 Safari iOS 4.2 Samsung Internet Android 1.0
DeviceMotionEvent() 构造函数
非标
Chrome 59 Edge ≤79 Firefox ? IE No Opera ? Safari ? WebView Android 59 Chrome Android 59 Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android 7.0
acceleration
Chrome Yes Edge 12 Firefox 6 IE No Opera Yes Safari ? WebView Android Yes Chrome Android Yes Firefox Android 6 Opera Android ? Safari iOS 4.2 Samsung Internet Android Yes
accelerationIncludingGravity
Chrome Yes Edge 12 Firefox 6 IE No Opera Yes Safari ? WebView Android Yes Chrome Android Yes Firefox Android 6 Opera Android Yes Safari iOS 4.2 Samsung Internet Android Yes
interval
Chrome Yes Edge 12 Firefox 6 IE No Opera Yes Safari ? WebView Android Yes Chrome Android Yes Firefox Android 6 Opera Android Yes Safari iOS 4.2 Samsung Internet Android Yes
rotationRate
Chrome Yes Edge 12 Firefox 6 IE No Opera Yes Safari ? WebView Android Yes Chrome Android Yes Firefox Android 6 Opera Android Yes Safari iOS 4.2 Samsung Internet Android Yes

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。
非标。预期跨浏览器支持较差。
非标。预期跨浏览器支持较差。

另请参阅