The deviceorientation
event is fired when fresh data is available from an orientation sensor about the current orientation of the device as compared to the Earth coordinate frame. This data is gathered from a magnetometer inside the device. See Orientation and motion data explained for details.
Bubbles | No |
---|---|
Cancelable | No |
Interface | DeviceOrientationEvent |
Event handler property | window.ondeviceorientation |
Examples
if (window.DeviceOrientationEvent) { window.addEventListener("deviceorientation", function(event) { // alpha: rotation around z-axis var rotateDegrees = event.alpha; // gamma: left to right var leftToRight = event.gamma; // beta: front back motion var frontToBack = event.beta; handleOrientationEvent(frontToBack, leftToRight, rotateDegrees); }, true); } var handleOrientationEvent = function(frontToBack, leftToRight, rotateDegrees) { // do something amazing };
Specifications
Specification | Status |
---|---|
DeviceOrientation Event Specification The definition of 'DeviceOrientation event' in that specification. |
Editor's Draft |
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
deviceorientation event | Chrome Full support 7 | Edge Full support ≤18 | Firefox
Full support
6
| IE ? | Opera Full support 12 | Safari Full support Yes | WebView Android Full support 3 | Chrome Android Full support 18 | Firefox Android
Full support
6
| Opera Android Full support 12 | Safari iOS Full support 4.2 | Samsung Internet Android Full support 1.0 |
Legend
- Full support
- Full support
- Compatibility unknown
- Compatibility unknown
- Uses a non-standard name.
- Uses a non-standard name.
See also
devicemotion
- Detecting device orientation
- Orientation and motion data explained
- Simulating orientation events on desktop browsers with the orientation-devtool