//shake a Shake action//Get acceleration Information//by listening to the previous step to obtain the X, Y, z value in a certain time range of the rate of change, whether the device has a shaking judgment. //in order to prevent the normal movement of the false, we need to set a suitable threshold for the rate of change. varShake_threshold = 4000; varlast_update = 0; varX, Y, z, last_x = 0, last_y = 0, last_z = 0; functionDevicemotionhandler (eventData) {varAcceleration =eventdata.accelerationincludinggravity; varCurtime =NewDate (). GetTime (); if((curtime-last_update) > 10) { varDifftime = Curtime-last_update; Last_update=Curtime; X=acceleration.x; Y=ACCELERATION.Y; Z=acceleration.z; varSpeed = Math.Abs (x +y + z-last_x-last_y-last_z)/difftime * 10000; if(Speed >shake_threshold) { $('. Slide_06_text '). FadeOut (); $('. milk_01 '). Animate ({top: ' 0 '},1000); $('. milk_02 '). Show (). Animate ({bottom: ' 0 '},2000); $('. yao_tips_01 '). Animate ({top: ' 5% '},1500); $('. yao_tips_02 '). Show (). Animate ({bottom: ' 5% '},2000); SetTimeout (function(){ $('. Slide_06 '). FadeOut (); $('. Slide_04 '). FadeIn (); },2500); } last_x=x; Last_y=y; Last_z=Z; } }
Mobile end H5 Shake event