Window: devicemotion event

The devicemotion event is fired at a regular interval and indicates the amount of physical force of acceleration the device is receiving at that time. It also provides information about the rate of rotation, if available.

Bubbles No
Cancelable No
Interface DeviceMotionEvent
Event handler property Window.ondevicemotion


function handleMotionEvent(event) {

    var x = event.accelerationIncludingGravity.x;
    var y = event.accelerationIncludingGravity.y;
    var z = event.accelerationIncludingGravity.z;

    // Do something awesome.

window.addEventListener("devicemotion", handleMotionEvent, true);


Specification Status
DeviceOrientation Event Specification
The definition of 'DeviceMotion event' in that specification.
Editor's Draft

Browser compatibility

BCD tables only load in the browser

See also