标签:
<!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>
标签:
原文地址:http://www.cnblogs.com/angelTeng/p/4630543.html