码迷,mamicode.com
首页 > 其他好文 > 详细

DeviceOrientationEvent笔记

时间:2015-07-08 17:53:12      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta content="initial-scale=1.0,user-scalable=no,maximum-scale=1,width=device-width" name="viewport">
  <meta content="initial-scale=1.0,user-scalable=no,maximum-scale=1" media="(device-height: 568px)" name="viewport">
  <meta content="yes" name="apple-mobile-web-app-capable">
  <meta content="black" name="apple-mobile-web-app-status-bar-style">
  <meta content="telephone=no" name="format-detection">
  <title>个人中心</title>

</head>
<body>

<script type="text/javascript">

  // 首先在页面上要监听运动传感事件
  function init(){
    if(window.DeviceOrientationEvent){
      window.addEventListener(‘deviceorientation‘, deviceMotionHandler, false);
      $("#yaoyiyaoyes").show();
    }
    else{
      $("#yaoyiyaono").show();
    }
  }


  var last_update = 0;
  var rotate;
  var last_rotate;

  function deviceMotionHandler(eventData){
    var curTime= new Date().getTime();
    var diffTime= curTime - last_update ;
    if(diffTime>100){
      last_update= curTime;
      rotate = eventData.gamma;
//      var speed = Math.abs(rotate - last_rotate) / diffTime * 10000;
      if(rotate>5 ){
        $("body").append("<p>>right</p>");
      }
      else if(rotate<-5 ){
        $("body").append("<p>left</p>");
      }
      last_rotate = rotate;
    }
  }

</script>
<div id="yaoyiyaoyes" style="font-size:20px;margin:10px;line-height:50px;display:none;">
    start!
</div>
<div id="yaoyiyaoresult" style="font-size:20px;margin:10px;line-height:50px;display:none;"></div>
<script>
  $(document).ready(function(){
    init();
  });
</script>
</body>
</html>

 

DeviceOrientationEvent笔记

标签:

原文地址:http://www.cnblogs.com/angelTeng/p/4630543.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!