if (window.DeviceOrientationEvent) {
window.addEventListener(
"deviceorientation",
(event) => {
const rotateDegrees = event.alpha; // alpha: rotation around z-axis
const leftToRight = event.gamma; // gamma: left to right
const frontToBack = event.beta; // beta: front back motion
handleOrientationEvent(frontToBack, leftToRight, rotateDegrees);
},
true,
);
}
function handleOrientationEvent(frontToBack, leftToRight, rotateDegrees) {
// do something amazing
}Window: deviceorientation event / notebook
Window: deviceorientation event
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.