http://m.laiwang.com/market/laiwang/alibabaxiaozhao2014.php?from=groupmessage&isappinstalled=0
http://dev.360.cn/m/pugongying.html?from=timeline&isappinstalled=0
http://leefd.lofter.com/post/330764_2448777
demo http://jsfiddle.net/592751v0/
<div> leftRightAngle: <b id="leftRightAngle"></b></div>
<div> frontBackAngle: <b id="frontBackAngle"></b></div>
<script>
var leftRightAngle,frontBackAngle;
if (window.DeviceOrientationEvent) {
window.addEventListener('deviceorientation', function (e) {
// 我们从事件“e”中获取角度值并转化成弧度值。
leftRightAngle = e.gamma / 90.0 * Math.PI / 2;
frontBackAngle = e.beta / 90.0 * Math.PI / 2;
document.getElementById('leftRightAngle').innerHTML = leftRightAngle;
document.getElementById('frontBackAngle').innerHTML = frontBackAngle;
}, false);
}
else if (window.OrientationEvent) { //另一个选项是Mozilla版本同样的东西
window.addEventListener('MozOrientation', function (e) {
//在这里将长度值当做一个单位,并转换成角度值,看起来运行的不错。
leftRightAngle = e.x * Math.PI / 2;
frontBackAngle = e.y * Math.PI / 2;
document.getElementById('leftRightAngle').innerHTML = leftRightAngle;
document.getElementById('frontBackAngle').innerHTML = frontBackAngle;
}, false);
}
else {
// 自然地,没有浏览器支持的大多数人会获取这个。
setStatus('Your device does not support orientation reading. Please use Android 4.0 or later, iOS (MBP laptop is fine) or similar platform.');
}
</script>