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.
This event is not cancelable and does not bubble.
Use the event name in methods like addEventListener()
, or set an event handler property.
addEventListener("deviceorientation", (event) => {});
ondeviceorientation = (event) => {};
if (window.DeviceOrientationEvent) {
window.addEventListener(
"deviceorientation",
(event) => {
const rotateDegrees = event.alpha;
const leftToRight = event.gamma;
const frontToBack = event.beta;
handleOrientationEvent(frontToBack, leftToRight, rotateDegrees);
},
true,
);
}
const handleOrientationEvent = (frontToBack, leftToRight, rotateDegrees) => {
};