This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The DeviceMotionEvent
provides web developers with information about the speed of changes for the device's position and orientation.
Warning: Currently, Firefox and Chrome do not handle the coordinates the same way. Take care about this while using them.
Constructor
DeviceMotionEvent.DeviceMotionEvent()
- Creates a new
DeviceMotionEvent
.
Properties
DeviceMotionEvent.acceleration
Read only- An object giving the acceleration of the device on the three axis X, Y and Z. Acceleration is expressed in m/s2.
DeviceMotionEvent.accelerationIncludingGravity
Read only- An object giving the acceleration of the device on the three axis X, Y and Z with the effect of gravity. Acceleration is expressed in m/s2.
DeviceMotionEvent.rotationRate
Read only- An object giving the rate of change of the device's orientation on the three orientation axis alpha, beta and gamma. Rotation rate is expressed in degrees per seconds.
DeviceMotionEvent.interval
Read only- A number representing the interval of time, in milliseconds, at which data is obtained from the device.
Example
window.addEventListener('devicemotion', function(event) { console.log(event.acceleration.x + ' m/s2'); });
Specifications
Specification | Status | Comment |
---|---|---|
DeviceOrientation Event Specification The definition of 'DeviceMotionEvent' in that specification. |
Editor's Draft | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
DeviceMotionEvent | Chrome Full support 11 | Edge Full support ≤18 | Firefox Full support 6 | IE No support No | Opera Full support 15 | Safari Full support 5 | WebView Android Full support ≤37 | Chrome Android Full support 18 | Firefox Android Full support 6 | Opera Android Full support 14 | Safari iOS Full support 4.2 | Samsung Internet Android Full support 1.0 |
DeviceMotionEvent() constructor | Chrome Full support 59 | Edge Full support ≤79 | Firefox ? | IE No support No | Opera ? | Safari ? | WebView Android Full support 59 | Chrome Android Full support 59 | Firefox Android ? | Opera Android ? | Safari iOS ? | Samsung Internet Android Full support 7.0 |
acceleration | Chrome Full support Yes | Edge Full support 12 | Firefox Full support 6 | IE No support No | Opera Full support Yes | Safari ? | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 6 | Opera Android ? | Safari iOS Full support 4.2 | Samsung Internet Android Full support Yes |
accelerationIncludingGravity | Chrome Full support Yes | Edge Full support 12 | Firefox Full support 6 | IE No support No | Opera Full support Yes | Safari ? | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 6 | Opera Android Full support Yes | Safari iOS Full support 4.2 | Samsung Internet Android Full support Yes |
interval | Chrome Full support Yes | Edge Full support 12 | Firefox Full support 6 | IE No support No | Opera Full support Yes | Safari ? | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 6 | Opera Android Full support Yes | Safari iOS Full support 4.2 | Samsung Internet Android Full support Yes |
rotationRate | Chrome Full support Yes | Edge Full support 12 | Firefox Full support 6 | IE No support No | Opera Full support Yes | Safari ? | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 6 | Opera Android Full support Yes | Safari iOS Full support 4.2 | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
- Non-standard. Expect poor cross-browser support.
- Non-standard. Expect poor cross-browser support.