DeviceOrientationEvent

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

DeviceOrientationEvent provides web developers with information from the physical orientation of the device running the web page.

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

构造函数

DeviceOrientationEvent.DeviceOrientationEvent()
创建新的 DeviceOrientationEvent .

特性

DeviceOrientationEvent.absolute 只读
A boolean that indicates whether or not the device is providing orientation data absolutely.
DeviceOrientationEvent.alpha 只读
A number representing the motion of the device around the z axis, express in degrees with values ranging from 0 to 360.
DeviceOrientationEvent.beta 只读
A number representing the motion of the device around the x axis, express in degrees with values ranging from -180 to 180. This represents a front to back motion of the device.
DeviceOrientationEvent.gamma 只读
A number representing the motion of the device around the y axis, express in degrees with values ranging from -90 to 90. This represents a left to right motion of the device.
DeviceOrientationEvent.webkitCompassHeading 只读
A number represents the difference between the motion of the device around the z axis of the world system and the direction of the north,  express in degrees with values ranging from 0 to 360.
DeviceOrientationEvent.webkitCompassAccuracy 只读
The accuracy of the compass means that the deviation is positive or negative. It's usually 10.

范例

window.addEventListener('deviceorientation', function(event) {
  console.log(event.alpha + ' : ' + event.beta + ' : ' + event.gamma);
});
					

规范

规范 状态 Comment
DeviceOrientation Event Specification 编者草案 Initial 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
DeviceOrientationEvent
Chrome 7
7
Before version 50, Chrome provided absolute values instead of relative values for this event. Developers still needing absolute values may use the ondeviceorientationabsolute 事件。
Edge ≤18 Firefox 6
6
Firefox 3.6, 4, and 5 supported mozOrientation instead of the standard DeviceOrientationEvent interface.
IE No Opera 15 Safari 5 WebView Android ≤37
≤37
Before version 50, Chrome provided absolute values instead of relative values for this event. Developers still needing absolute values may use the ondeviceorientationabsolute 事件。
Chrome Android 18
18
Before version 50, Chrome provided absolute values instead of relative values for this event. Developers still needing absolute values may use the ondeviceorientationabsolute 事件。
Firefox Android 6
6
Firefox 3.6, 4, and 5 supported mozOrientation instead of the standard DeviceOrientationEvent interface.
Opera Android 14 Safari iOS 4.2 Samsung Internet Android 1.0
1.0
Before Samsung Internet 5.0, Samsung Internet provided absolute values instead of relative values for this event. Developers still needing absolute values may use the ondeviceorientationabsolute 事件。
DeviceOrientationEvent() 构造函数
非标
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
absolute
Chrome 7 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
alpha
Chrome 7 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
beta
Chrome 7 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
gamma
Chrome 7 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

图例

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

另请参阅