<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "UTF-8"> <title>Shaking judgment</title> <Metaname= "Viewport"content= "Width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, User-scalable=no"/></Head><Body> <DivID= "status">[-Please shake the device-]</Div> <Divclass= "link"style= "position:fixed;bottom:20px"> <ahref= "Demo.htm">1, access to equipment information</a><BR/> <ahref= "Demo_1.htm">2. Shaking judgment</a><BR/> <ahref= "Demo_2.htm">3, simple simulation shake a shake</a> </Div> <Script> varShake_threshold= -; varlast_update= 0; varx=y=Z=last_x=last_y=last_z= 0; if(window. Devicemotionevent) {Window.addeventlistener ('devicemotion', Devicemotionhandler,false); } Else{alert ('This device does not support Devicemotion events'); } functionDevicemotionhandler (eventData) {varAcceleration=eventdata.accelerationincludinggravity; varCurtime= NewDate (). GetTime (); if((Curtime-last_update)> -) { varDifftime=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; varStatus=document.getElementById ("Status"); if( speed>shake_threshold) { vartext= "x:"+x+"<br/>y:"+y+"<br/>z:"+Z+"<br/>speed:"+Speed ; Status.innerhtml=text; } last_x=x; Last_y=y; Last_z=Z; } } </Script></Body></HTML>
HTML5 realization of mobile phone shake-shake function (B)