DeviceOrientationEvent

Baseline 2023 *
Newly available

Since September 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

* Some parts of this feature may have varying levels of support.

安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。

DeviceOrientationEvent端末方向イベントのインターフェイスで、ウェブ開発者にウェブページを実行する端末の物理的な方向からの情報を提供します。

Event DeviceOrientationEvent

コンストラクター

DeviceOrientationEvent.DeviceOrientationEvent()

新しい DeviceOrientationEvent を作成します。

インスタンスプロパティ

DeviceOrientationEvent.absolute 読取専用

論理値で、端末が絶対に方向データを提供するかどうかを示します。

DeviceOrientationEvent.alpha 読取専用

数値で、端末の Z 軸の回転量を表し、 0 (含む)から 360 (含まない)までの範囲の値で表します。

DeviceOrientationEvent.beta 読取専用

数値で、端末の X 軸の回転量を表し、 -180 (含む)から 180 (含まない)までの範囲の値で表します。これは端末の前後方向の動きを表します。

DeviceOrientationEvent.gamma 読取専用

数値で、端末の Z 軸の回転量を表し、 -90 (含む)から 90 (含まない)までの範囲の値で表します。これは端末の左右方向の動きを表します。

DeviceOrientationEvent.webkitCompassHeading 非標準 読取専用

数値で、ワールドシステムの Z 軸を中心とした端末の動きと北の方向との差を表し、 0 から 360 の範囲の値で度数で表します。

DeviceOrientationEvent.webkitCompassAccuracy 非標準 読取専用

コンパスの精度で、偏差が正の値または負の値を意味しています。通常は 10 です。

js
window.addEventListener("deviceorientation", (event) => {
  console.log(`${event.alpha} : ${event.beta} : ${event.gamma}`);
});

仕様書

Specification
Device Orientation and Motion
# deviceorientation

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
DeviceOrientationEvent
DeviceOrientationEvent() constructor
absolute
alpha
beta
gamma
requestPermission() static method
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

関連情報