<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "UTF-8"> <title>Get device information</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"></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> if(window. Devicemotionevent) {Window.addeventlistener ('devicemotion', Devicemotionhandler,false); } Else{alert ('This device does not support Devicemotion events'); } functionDevicemotionhandler (eventData) {varAcceleration=eventdata.accelerationincludinggravity, x, Y, Z; X=acceleration.x; Y=ACCELERATION.Y; Z=acceleration.z; document.getElementById ("Status"). InnerHTML= "x:"+x+"<br/>y:"+y+"<br/>z:"+Z; } </Script></Body></HTML>
HTML5 mobile phone Shake function (a)