Skip to content

Instantly share code, notes, and snippets.

@vlenhart
Created May 23, 2011 08:45
Show Gist options
  • Save vlenhart/986416 to your computer and use it in GitHub Desktop.
Save vlenhart/986416 to your computer and use it in GitHub Desktop.
Using deviceorientation values from Webkit browsers like MozOrientation values.
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