- 当前 Bug 的表现(可附上截图)
- 预期表现
- 复现路径
- 提供一个最简复现 Demo
if (window.DeviceMotionEvent) {
window.addEventListener(‘devicemotion’, deviceMotionHandler, false);
} else {
alert(‘您的手机不支持摇一摇’);
}
var SHAKE_THRESHOLD = 200;
var last_update = 0;
var initnum = 0;
var x = y = z = last_x = last_y = last_z = 0;
var num = 0;
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;
var x1 = Math.abs(x-last_x);
var y1 = Math.abs(y-last_y);
var z1 = Math.abs(z-last_z);
var max =0;
if(x1>y1){
if(x1>z1){
max=x1;
}else{
max=z1;
}
}else {
if(y1>z1){
max=y1;
}else{
max=z1;
}
}
if(max>40){
}
}else if(max<5&&isprint){
}
last_x = x;
last_y = y;
last_z = z;
}
}