找传奇、传世资源到传世资源站!

html5 php 陀螺仪(重力感应)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

html5 php 陀螺仪(重力感应) JavaScript基础-第1张<!doctype html><head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <title>手机摇一摇测试</title> </head> <body> <script> window.onload = function(){ if(window.DeviceOrientationEvent){ window.addEventListener('deviceorientation',DeviceOrientationHandler,false);}else{ alert("您的浏览器不支持DeviceOrientation");} }; var last_update = 0; function deviceMotionHandler(eventData) { var acceleration = eventData.accelerationIncludingGravity; var rawAcceleration = "[" Math.round(acceleration.x) ", " Math.round(acceleration.y) ", " Math.round(acceleration.z) "]"; var facingUp = -1; if (acceleration.z > 0) { facingUp = 1; } // 根据重力通过 acceleration.x|y 转换得到加速值, // 运用重力加速度9.81来计算得到一个百分比然后乘以转换角度90 var tiltLR = Math.round(((acceleration.x) / 9.81) * -90); var tiltFB = Math.round(((acceleration.y 9.81) / 9.81) * 90 * facingUp); var text=document.getElementById("text"); var curTime = new Date().getTime(); if ((curTime - last_update) > 100) { var diffTime = curTime - last_update; last_update = curTime; x = acceleration.x; y = acceleration.y; z = acceleration.z; last_x = tiltLR; last_y = tiltFB; last_z = z; text.innerHTML="x" x "<br/>y" y "</br>z" z; } }function DeviceOrientationHandler(event){ var alpha = event.alpha, beta = event.beta, gamma = event.gamma; var dataContainerOrientation=document.getElementById("result"); var stage=document.getElementById("text"); if(alpha != null || beta != null || gamma != null){ dataContainerOrientation.innerHTML = "alpha:" alpha "<br />beta:" beta "<br />gamma:" gamma; window.addEventListener('devicemotion', deviceMotionHandler, false); }else{ dataContainerOrientation.innerHTML = "当前浏览器不支持DeviceOrientation"; }} </script><div id="text"></div> <div id="result">cdc</div></body></html>

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复