Use HTML5 to achieve a similar phone shake function and play music.
1, deviceorientation: Encapsulate the direction sensor data events, you can get the mobile phone in the static state of the direction of data, such as the angle of the mobile phone, orientation, orientation and so on.
2, devicemotion: The event that encapsulates the motion sensor data, can get the motion acceleration of the mobile phone.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6E/E0/wKiom1WKWyKygBADAAJt2B9fiz8238.jpg "title=" 005wh7uyzy6kxdjtdui1e&690.jpg "alt=" Wkiom1wkwykygbadaajt2b9fiz8238.jpg "/>
JS as follows:
<scirpt>var shake_threshold = 3000;var last_update = 0;var x = y = z = last_x = last_y = last_z = 0;function Init () {if (window. devicemotionevent) {window.addeventlistener (' devicemotion ', devicemotionhandler, false);} else {alert (' not support mobile event ');}} Function 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 &NBSP;-&NBSP;LAST_Y&NBSP;-&NBSP;LAST_Z) / difftime * 10000;if (Speed > shake_threshold) {//detected a shake, 5 seconds after the jump (during this period played a shake of the sound) alert ("Shake"); Media.setattribute ("src", "http://dx.sc.chinaz.com/files/download/sound1/201410/5018.wav"); Media.load (); Media.play (); SetTimeout (function () {location.href= ' http://www.baidu.com ';},5000);}} Last_x = x;last_y = y;last_z = z;}} </script>
The HTML5 page is as follows:
<! doctype html>
Try it on the phone ....
HTML5 to realize the function of shaking the phone