Principle: Use DeviceMotion to implement. For an introduction to DeviceMotion, you can view
https://developer.mozilla.org/en-US/docs/Web/Reference/Events /devicemotion
Through DeviceMotionEvent, you can get the x, y, and z attributes of accelerationIncludingGravity, and determine whether the device has shaken based on the changes in the x, y, and z attributes. The shaking event occurred.
accelerationIncludeingGravity description:
The acceleration of the device. This value includes the effect of gravity, and may be the only value available on devices that don't have a gyroscope to allow them to properly remove gravity from the data.
The code is as follows:
html5使用DeviceMotionEvent实现摇一摇 请执行摇一摇
This article introduces the function of shaking through html5. For more related content, please pay attention to php Chinese website.
Related recommendations:
How to view and modify auto_increment through MySql
##How to generate a web desktop shortcut through php Method
Use js traversal to obtain data in the table
The above is the detailed content of How to implement the shake function through html5. For more information, please follow other related articles on the PHP Chinese website!