Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created February 8, 2010 04:54
Show Gist options
  • Save hitode909/297885 to your computer and use it in GitHub Desktop.
Save hitode909/297885 to your computer and use it in GitHub Desktop.
<html>
<body>
<script>
var current = { x: 0.0, y: 0.0, z: 0.0 };
window.addEventListener("MozOrientation",
function(data) {
var xyz = ['x', 'y', 'z'];
for(var i = 0;i<xyz.length;i++){
var sum = Math.abs(data.x) + Math.abs(data.y) + Math.abs(data.z);
if (data[xyz[i]] > 0) {
document.querySelector("div#"+xyz[i]).style.width = data[xyz[i]] * 300 + 'px';
document.querySelector("div#"+xyz[i]).style.marginLeft = '300px';
} else {
document.querySelector("div#"+xyz[i]).style.width = data[xyz[i]] * -300 + 'px';
document.querySelector("div#"+xyz[i]).style.marginLeft = (300 + data[xyz[i]] * 300) + 'px';
}
}
}, true);
</script>
<div id="x" style="background: #f00; margin-left: 300px; height: 90px;" >x</div>
<div id="y" style="background: #0f0; margin-left: 300px; height: 90px;" >y</div>
<div id="z" style="background: #00f; margin-left: 300px; height: 90px;" >z</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment