//简单的摇一摇触发代码

if (window.DeviceMotionEvent) {                   window.addEventListener('devicemotion',deviceMotionHandler, false);           }          var speed = 30;//speed         var x...

if (window.DeviceMotionEvent) { 

                 window.addEventListener('devicemotion',deviceMotionHandler, false);  

        } 

        var speed = 30;//speed

        var x = y = z = lastX = lastY = lastZ = 0;

        function deviceMotionHandler(eventData) {  

          var acceleration =eventData.accelerationIncludingGravity;

                x = acceleration.x;

                y = acceleration.y;

                z = acceleration.z;

                if(Math.abs(x-lastX) > speed || Math.abs(y-lastY) > speed || Math.abs(z-lastZ) > speed) {

                    //简单的摇一摇触发代码

                    alert(1);

                }

                lastX = x;

                lastY = y;

                lastZ = z;

        }


 window.addEventListener("compassneedscalibration", function(event) {

      alert('您的罗盘需要校准,请将设备沿数字8方向移动。');

      event.preventDefault();

  }, true);


 window.addEventListener("devicemotion", function(event) {

      // 处理event.acceleration、event.accelerationIncludingGravity、

      // event.rotationRate和event.interval

  }, true);


  window.addEventListener("deviceorientation", function(event) {

      // 处理event.alpha、event.beta及event.gamma

  }, true);

  • 发表于 2018-08-17 09:35
  • 阅读 ( 710 )
  • 分类:Flash专区

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
不写代码的码农
皮卡丘先生

交互动画课件制作

13 篇文章

作家榜 »

  1. 苍老师 16 文章
  2. 大北兔 15 文章
  3. facaimao 14 文章
  4. 皮卡丘先生 13 文章
  5. 王迎保 10 文章
  6. hero 10 文章
  7. vien007 7 文章
  8. ningbnii 4 文章