• HTML5实现摇一摇


    var isyao=false;//控制强烈摇动,连续触发事件
            //手机摇动事件
            _self.ShakeMobileEven=function(){
                if (window.DeviceMotionEvent) {                
                    window.addEventListener('devicemotion', deviceMotionHandler, false);                                
                } else {
                    alertShow('本设备不支持devicemotion事件');
                }
                var speed = 23;
                var x = y = z = lastX = lastY = lastZ = 0;
                function deviceMotionHandler(event) {
                    if(isyao==true){
                        return;
                    }
                    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) {
                        isyao=true;
                        //摇动成功执行的代码在此处
                    }
                    lastX = x;
                    lastY = y;
                    lastZ = z;
                }           
            }
    

      另外,更多摇动实例参考:http://download.csdn.net/detail/yinluhui/8944075

  • 相关阅读:
    django rest_framework中将json输出字符强制为utf-8编码
    Java
    Java
    Oracle
    IDEA
    Ubuntu
    Ubuntu
    Ubuntu
    Ubuntu
    Oracle
  • 原文地址:https://www.cnblogs.com/yinluhui0229/p/4686733.html
Copyright © 2020-2023  润新知