Home >Web Front-end >H5 Tutorial >Implement WeChat shake function based on html5 DeviceOrientation_html5 tutorial skills
In HTML5, the DeviceMotion event provided by the DeviceOrientation feature encapsulates the device's motion sensor time. By changing the time, you can obtain the device's motion status, acceleration and other data (there is also a deviceOrientation event that provides device angle, orientation and other information) .
Determining the motion status of the device through DeviceMotion can help us achieve the "shake" interactive effect on the web page.
Motion event monitoring
Get acceleration information
The "shake" action means that the device moves a certain distance within a certain period of time. Therefore, by monitoring the change rate of the x, y, z values obtained in the previous step within a certain time range, you can determine whether the device has Make a shaking judgment. In order to prevent misjudgment of normal movement, an appropriate critical value needs to be set for the rate of change.
The effect is as shown in the picture: