Var isyao=false;//control strongly shakes, continuous trigger events//Phone Shake event _self. Shakemobileeven=function () {if (window. Devicemotionevent) {window.addeventlistener (' devicemotion ', Devicemotionhandler, false); } else {alertshow (' This device does not support devicemotion events '); } var = 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; The code that shakes successfully executes here} LASTX = x; Lasty = y; LaStZ = Z; } }
In addition, more shaking example reference: http://download.csdn.net/detail/yinluhui/8944075
HTML5 The realization shakes a shake