The DeviceMotionEvent() constructor creates a new DeviceMotionEvent object.
On this page
DeviceMotionEvent: DeviceMotionEvent() constructor
Syntax
js
new DeviceMotionEvent(type)
new DeviceMotionEvent(type, options)
Parameters
-
type -
A string with the name of the event. It is case-sensitive and browsers always set it to
devicemotion. optionsOptional-
An object that, in addition of the properties defined in
Event(), can have the following properties:-
acceleration -
A
DeviceMotionEventAccelerationobject giving the acceleration of the device on the three axis X, Y and Z. Acceleration is expressed in m/s². -
accelerationIncludingGravity -
A
DeviceMotionEventAccelerationobject giving the acceleration of the device on the three axis X, Y and Z with the effect of gravity. Acceleration is expressed in m/s². -
rotationRate -
A
DeviceMotionEventRotationRateobject giving the rate of change of the device's orientation on the three orientation axis alpha, beta and gamma. Rotation rate is express in degrees per seconds. intervalOptional-
A number representing the interval of time, in milliseconds, at which data is obtained from the device. It defaults to
0.
-
Return value
A new DeviceMotionEvent object.
Specifications
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
DeviceMotionEvent |
59 | 14 | 29 | No | 46 | No | 59 | 59 | 29 | 43 | No | 7.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent