Skip to content

Instantly share code, notes, and snippets.

@imRohan
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imRohan/179ddca36ae5f3b166dd to your computer and use it in GitHub Desktop.
Save imRohan/179ddca36ae5f3b166dd to your computer and use it in GitHub Desktop.
Device Motion
if (window.DeviceMotionEvent == undefined) {
// No Sensor Detected
} else {
window.ondevicemotion = function (event) {
// Grab x/y vals
ax = Math.round(Math.abs(event.accelerationIncludingGravity.x));
ay = Math.round(Math.abs(event.accelerationIncludingGravity.y));
// Check if Device is Tilted
if (ax !== 0 | ay !== 0){
//Device is tilted
} else {
//Device is flat
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment