DeviceMotionEvent

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.

DeviceMotionEvent インターフェイスは、ウェブ開発者に端末の位置と方向の変化のスピードに関する情報を提供します。

警告: 現在、Firefox と Chrome は同じ方法で座標を処理しません。これらを使用する際は、注意してください。

Event DeviceMotionEvent

コンストラクター

DeviceMotionEvent()

新しい DeviceMotionEvent を生成します。

プロパティ

DeviceMotionEvent.acceleration 読取専用

3 つの軸 X、Y、Z 上の端末の加速度を与えるオブジェクトです。加速度は m/s² で表されます。

DeviceMotionEvent.accelerationIncludingGravity 読取専用

X、Y、Z 上の端末の加速度を重力度込みで与えるオブジェクトです。加速度は m/s² で表されます。

DeviceMotionEvent.rotationRate 読取専用

3 つの方向軸アルファ、ベータ、ガンマ上の端末の向きの変化率を与えるオブジェクトです。回転速度は 1 秒あたりの度数で表されます。

DeviceMotionEvent.interval 読取専用

端末からデータを取得する間隔(ミリ秒)を表す数値です。

js
window.addEventListener("devicemotion", (event) => {
  console.log(`${event.acceleration.x} m/s2`);
});

仕様書

Specification
DeviceOrientation Event Specification
# devicemotion

ブラウザーの互換性

BCD tables only load in the browser

関連情報