Last active
August 29, 2015 14:21
-
-
Save imRohan/179ddca36ae5f3b166dd to your computer and use it in GitHub Desktop.
Device Motion
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
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