21模块-orientation【管理设备的方向信息】

Orientation模块管理设备的方向信息,包括alpha、beta、gamma三个方向信息,通过plus.orientation可获取设备方向管理对象。

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>心得</title>
<script type="text/javascript">
var temp_obj = null;
function one(){
plus.orientation.getCurrentOrientation(function(e){
alert('获取成功'+e.trueHeading);
},function(e){
alert('获取失败'+e.message);
});
}
function two(){//功能和多次调用 getCurrentOrientation 一样
temp_obj = plus.orientation.watchOrientation(function(e){
document.getElementById("imglist").innerHTML = "<li>"+parseInt(e.trueHeading)+"度</li>";
},function(e){
alert('获取失败'+e.message);
});
}
function three(){
plus.orientation.clearWatch(temp_obj);
}
</script>
</head>
<style>
li{line-height: 40px; height: 40px; border-bottom: #ccc dashed 1px;}
</style>
<body>
<ul id="imglist"></ul>
<ul>
<li onclick="one()">获取当前设备的方向信息</li>
<li onclick="two()">监听设备方向信息的变化</li>
<li onclick="three()">关闭监听设备方向信息</li>
</ul>
</body>
</html>

 

posted @ 2018-07-18 15:54  学画人生  阅读(445)  评论(0编辑  收藏  举报