Skip to content

Instantly share code, notes, and snippets.

@topheman
Created September 27, 2013 14:48
Show Gist options
  • Save topheman/6729788 to your computer and use it in GitHub Desktop.
Save topheman/6729788 to your computer and use it in GitHub Desktop.
Deviceorientation / orientationchange - tests
<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