Skip to content

Instantly share code, notes, and snippets.

@thelucre
Last active December 28, 2018 20:45
Show Gist options
  • Save thelucre/35a81dd7f8c074bbef1b9bd63928eb48 to your computer and use it in GitHub Desktop.
Save thelucre/35a81dd7f8c074bbef1b9bd63928eb48 to your computer and use it in GitHub Desktop.
deviceorientation normalization notes
// check for window.orientation || window.screen.orientation.angle
let h;
switch (window.screen.orientation.angle) {
case 0:
h = "portrait";
break;
case 180:
h = "portrait-upside-down";
break;
case -90:
h = "landscape-clockwise";
break;
case 90:
h = "landscape-counter-clockwise";
break;
}
window.addEventListener("deviceorientation",
function(a) {
switch (h) {
case "portrait":
(I = Math.round(100 * a.beta) / 100 - 30),
(F = Math.round(100 * a.gamma) / 100);
break;
case "portrait-upside-down":
(I = -1 * (Math.round(100 * a.beta) / 100 + 30)),
(F = (Math.round(100 * a.gamma) / 100) * -1);
break;
case "landscape-clockwise":
(F = (Math.round(100 * a.beta) / 100) * -1),
(I = Math.round(100 * a.gamma) / 100 - 30);
break;
case "landscape-counter-clockwise":
(F = Math.round(100 * a.beta) / 100),
(I = -1 * (Math.round(100 * a.gamma) / 100 + 30));
break;
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment