这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
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.
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.
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);
});
| 规范 | 状态 | 注释 |
|---|---|---|
| DeviceOrientation Event Specification | 编者草案 | 最初的规范。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
DeviceOrientationEvent
|
Chrome
7
|
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
|
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 |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
非标。预期跨浏览器支持较差。
见实现注意事项。
deviceorientation
DeviceMotionEvent
devicemotion
DeviceOrientationEvent