DeviceMotionEvent: DeviceMotionEvent() コンストラクター

DeviceMotionEvent() コンストラクターは、新しい DeviceMotionEvent オブジェクトを作成します。

構文

js
new DeviceMotionEvent(type)
new DeviceMotionEvent(type, options)

引数

type

文字列で、このイベントの名前が入ります。 大文字小文字の区別があり、ブラウザーは常に devicemotion に設定します。

options 省略可

オブジェクトで、Event() に定義されているプロパティに加えて、以下のプロパティを持つことができます。

acceleration

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

accelerationIncludingGravity

DeviceMotionEventAcceleration オブジェクトで、端末の加速度を X、Y、Z の 3 軸と、重力の影響で表します。 加速度は m/s² で表されます。

rotationRate

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

interval 省略可

端末からデータを取得する時間間隔をミリ秒単位で表します。既定値では 0 です。

返値

新しい DeviceMotionEvent オブジェクトです。

仕様書

Specification
DeviceOrientation Event Specification
# dom-devicemotionevent-devicemotionevent

ブラウザーの互換性

BCD tables only load in the browser