码迷,mamicode.com
首页 > Web开发 > 详细

html5重力感应事件

时间:2016-08-10 12:15:30      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:

 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 =event.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;
            }

摇一摇触发事件,感觉还是蛮高大上的

html5重力感应事件

标签:

原文地址:http://www.cnblogs.com/djdliu/p/5755894.html

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