DeviceOrientationEvent: DeviceOrientationEvent() constructor

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The DeviceOrientationEvent() constructor creates a new DeviceOrientationEvent object.

Syntax

js
new DeviceOrientationEvent(type)
new DeviceOrientationEvent(type, options)

Parameters

type

A string with the name of the event. It is case-sensitive and browsers set it to deviceorientation or deviceorientationabsolute. In the latter case, options.absolute is always true.

options Optional

An object that, in addition of the properties defined in Event(), can have the following properties:

alpha Optional

A number representing the motion of the device around the z axis, expressed in degrees with values ranging from 0 to 360. It defaults to null.

beta Optional

A number representing the motion of the device around the x axis, expressed in degrees with values ranging from -180 to 180. This represents a front to back motion of the device. It defaults to null.

gamma Optional

A number representing the motion of the device around the y axis, expressed in degrees with values ranging from -90 to 90. This represents a left to right motion of the device. It defaults to null.

absolute

A boolean value that indicates whether or not the device is providing orientation data absolutely. It defaults to false.

Return value

A new DeviceOrientationEvent object.

Specifications

Specification
Device Orientation and Motion
# dom-deviceorientationevent-deviceorientationevent

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
DeviceOrientationEvent() constructor
Chrome – Full support
Chrome 59 (Release date: 2017-06-05)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 17 (Release date: 2012-11-20)
footnote Full support
Opera – Full support
Opera 46 (Release date: 2017-06-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 59 (Release date: 2017-06-06)
footnote Full support
Firefox for Android – Full support
Firefox for Android 17 (Release date: 2012-11-20)
footnote Full support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 59 (Release date: 2017-06-06)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support