</title> <script type="text/javascript"> var SHAKE_THRESHOLD = 3000; var last_update = 0; var x=y=z=last_x=last_y=last_z=0; var media; function init(){ last_update=new Date().getTime(); media= document.getElementById("musicBox"); if (window.DeviceMotionEvent) { window.addEventListener('devicemotion',deviceMotionHandler, false); } else{ alert('not support mobile event'); } } function deviceMotionHandler(eventData) { var acceleration =eventData.accelerationIncludingGravity; 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; var speed = Math.abs(x +y + z - last_x - last_y - last_z) / diffTime * 10000; if (speed > SHAKE_THRESHOLD) { alert("shaked"); } last_x = x; last_y = y; last_z = z; } } </script> </head> <body onload="init()"> html5手机摇一摇功能,摇一摇试试看 </body> </html>


相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2021-08-02
  • 2021-11-20
猜你喜欢
  • 2021-06-13
  • 2021-05-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-16
相关资源
相似解决方案