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 SpecificationThe 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.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
deviceorientation event
|
Chrome
Full support 7 |
Edge
Full support ≤18 |
Firefox Full support 6 Full support 6 No support 3.6 — 6 Alternate Name' Uses the non-standard name: |
IE
? |
Opera
Full support 12 |
Safari
Full support Yes |
WebView Android
Full support 3 |
Chrome Android
Full support 18 |
Firefox Android Full support 6 Full support 6 No support 4 — 6 Alternate Name' Uses the non-standard name: |
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
Window: deviceorientation event by Mozilla Contributors is licensed under CC-BY-SA 2.5.