Skip to content

Instantly share code, notes, and snippets.

@siyo siyo/anglemeter.html
Last active Dec 18, 2015

Embed
What would you like to do?
<!Doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>angle meter sample</title>
<style type="text/css">
.container{
width: 200px;
text-align: center;
padding: 20px;
float:left;
}
.angle-meter {
border: solid 10px;
border-color: gray;
border-radius: 50%;
height: 200px;
width: 200px;
}
.triangle-up {
margin-right:auto;
margin-left:auto;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 100px solid #f66;
}
.triangle-down {
margin-right:auto;
margin-left:auto;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 100px solid #666;
}
</style>
<script>
window.addEventListener("load",function(){
var meter1 = document.getElementById('pitch');
var meter2 = document.getElementById('yaw');
var meter3 = document.getElementById('roll');
window.addEventListener('deviceorientation', function(ev) {
meter1.style.webkitTransform = "rotate(" + ev.beta + "deg)";
meter2.style.webkitTransform = "rotate(" + ev.alpha + "deg)";
meter3.style.webkitTransform = "rotate(" + ev.gamma + "deg)";
});
}, false);
</script>
</head>
<body>
<div class="container">
<p>Pitch</p>
<div id="pitch" class="angle-meter">
<div class="triangle-up"></div>
<div class="triangle-down"></div>
</div>
</div>
<div class="container">
<p>Yaw</p>
<div id="yaw" class="angle-meter">
<div class="triangle-up"></div>
<div class="triangle-down"></div>
</div>
</div>
<div class="container">
<p>Roll</p>
<div id="roll" class="angle-meter">
<div class="triangle-up"></div>
<div class="triangle-down"></div>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.