1. DeviceOrientation: A event that encapsulates the directional sensor data to obtain the direction data in the static state of the mobile phone, such as the angle, orientation, orientation of the mobile phone.
2. DeviceMotion: Event with a motion sensor data encapsulates data such as motion acceleration in the state of mobile phone motion.
Not much to say directly to the code:
Javascript:
Var jsonObject = NULL; // When the page is loaded, it will execute window.Onload Window.onload = Function () {var Times = -1; // Record the number of shakes_time = 0; VAR BORDESPEED = 800; // Add Change Critical VAR X = Y = Z = Last_x = Last_y = Last_z = 0; if (Window.DeviceMotionEvent) {Window.adDeventListener ('Devicemotion', Shake, FALSE);} Else {Alert ('Your device does not support shake one Shake Oh ");} // Every time the mobile phone moves, the code of shake function is executed. ettime (); VAR DIFFTIME = Curtime -last_time; // Judge if (difftime> 100) {x = acceleration.x; y = acceleration.y; z = acceleration.z; var speard = math.abs (x + y + z -Last_x- Last_y -Last_z) / Difftime * 10000; // Judging that the phone does shake instead of normal mobile if (Speed> Borderspeed) {times ++; document.GetelementByid (text). iMes; // User's WeChat nickname and The avatar connection can be sent once, no need to send if (times == 0) {document.forms [insertform] .headimg.value = img; document.forms [insertform] .user.value = nickName;} DO cumeent. Forms [Insertform] .time.value = Times;} Last_time = Curtime; Last_x = x; Last_y = y; last_z = z;}}}}}}}}html:
<IMG SRC = Hand.png> <br/> <font size = 16 color = red ID = text> </font>Summarize
The above is what I introduced to you based on HTML5 -based implementation similar to WeChat mobile phone shaking function (calculate the number of shakes). I hope it will be helpful to everyone. If you have any questions, please leave me a message. Xiaobian will reply to everyone in time. Essence Thank you very much for your support for the VEVB Wulin website!