Created
September 27, 2013 14:48
-
-
Save topheman/6729788 to your computer and use it in GitHub Desktop.
Deviceorientation / orientationchange - tests
This file contains hidden or 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
<DOCTYPE html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<div id="dataContainerOrientation"> | |
No device orientation data | |
</div> | |
<script> | |
function init() { | |
//Find our div containers in the DOM | |
var dataContainerOrientation = document.getElementById('dataContainerOrientation'); | |
//Check for support for DeviceOrientation event | |
if(window.DeviceOrientationEvent) { | |
window.addEventListener('deviceorientation', function(event) { | |
var alpha = event.alpha; | |
var beta = event.beta; | |
var gamma = event.gamma; | |
var compass = event.webkitCompassHeading; | |
var orientation = window.orientation; | |
if(alpha!=null || beta!=null || gamma!=null) | |
dataContainerOrientation.innerHTML = 'Left/Right [gamma]: ' + gamma + '<br/>Front/Back [beta]: ' + beta + '<br />Direction [alpha]: ' + alpha + '<br />Compass [webkitCompassHeading]: ' + compass + '<br />Orientation [orientation]: ' + orientation; | |
}, false); | |
} | |
} | |
init(); | |
/*function testOrientation(event){ | |
alert(event.orientation); | |
} | |
window.onorientationchange = testOrientation;*/ | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment