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

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

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

DeviceOrientationEvent 提供了網頁開發者關於目前瀏覽頁面之裝置的物理旋轉方向資訊。

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

屬性

DeviceOrientationEvent.absolute Read only
A boolean that indicates whether or not the device is providing orientation data absolutely.
DeviceOrientationEvent.alpha Read only
A number representing the motion of the device around the z axis, express in degrees with values ranging from 0 to 360
DeviceOrientationEvent.beta Read only
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 Read only
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.

範例

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

規範

Specification Status Comment
Device Orientation Events Working Draft Initial specification.

瀏覽器相容性

  
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 7.0 [1] (Yes) 6 [2] ? ? ?
  
Feature Android Android Webview Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support 3.0 (Yes) [1] (Yes) 6 [2] No support No support 4.2 (Yes) [1]

[1] Before version 50, Chrome provided absolute values instead of relative values for this event. Developers still needing absolute values may use the ondeviceorientationabsolute event.

[2] Firefox 3.6, 4, and 5 supported mozOrientation instead of the standard DeviceOrientationEvent interface

參見

文件標籤與貢獻者

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