Created
May 23, 2011 08:45
-
-
Save vlenhart/986416 to your computer and use it in GitHub Desktop.
Using deviceorientation values from Webkit browsers like MozOrientation values.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('deviceorientation', updateOrient, false); | |
window.addEventListener("MozOrientation", updateOrient, false); | |
function updateOrient(e) { | |
if (e.gamma && e.beta) { | |
e.x = -e.gamma / (180 / Math.PI); | |
e.y = -e.beta / (180 / Math.PI); | |
} | |
// use e.x and e.y here... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
adapted from: https://developer.mozilla.org/en/Detecting_device_orientation#Normalizing_between_Gecko_and_WebKit