Created
March 28, 2011 14:34
-
-
Save karlwestin/890568 to your computer and use it in GitHub Desktop.
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
//Accelerometer Javascript example by @karlwestin, Nerd Communications, Berlin | |
// Firefox, works on desktop too | |
window.addEventListener("MozOrientation", updateText, true); | |
// Mobile Safari | |
window.addEventListener("devicemotion", updateText, true); | |
function updateText(e) { | |
if(!!e.x) | |
// Firefox | |
updateCounter(e.x*10, e.y*10, e.z*10); | |
else if (!!e.accelerationIncludingGravity) | |
// Mobile Safari | |
updateCounter(e.accelerationIncludingGravity.x, e.accelerationIncludingGravity.y, e.accelerationIncludingGravity.z); | |
else | |
alert("you don't really support devicemotion, do you?"); | |
} | |
function updateCounter(x, y, z) { | |
document.getElementById("xAxis").innerHTML = x; | |
document.getElementById("yAxis").innerHTML = y; | |
document.getElementById("zAxis").innerHTML = z; | |
} |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment