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

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

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

構文

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

引数

type

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

options 省略可

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

acceleration 省略可

DeviceMotionEventAcceleration オブジェクトで、端末の加速度を X、Y、Z の 3 軸で表します。加速度は m/s² で表されます。指定されなかった場合、オブジェクト内のすべてのプロパティが null になります。

accelerationIncludingGravity 省略可

DeviceMotionEventAcceleration オブジェクトで、端末の加速度を X、Y、Z の 3 軸と、重力の影響で表します。加速度は m/s² で表されます。指定されなかった場合、オブジェクト内のすべてのプロパティが null になります。

rotationRate 省略可

DeviceMotionEventRotationRate オブジェクトで、端末の向きの変化率をアルファ、ベータ、ガンマの 3 方向の軸で表します。回転率は秒あたりの角度で表されます。指定されなかった場合、オブジェクト内のすべてのプロパティが null になります。

interval 省略可

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

返値

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

仕様書

Specification
Device Orientation and Motion
# dom-devicemotionevent-devicemotionevent

ブラウザーの互換性

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
DeviceMotionEvent() constructor

Legend

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

Full support
Full support
No support
No support