Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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