原理:使用DeviceMotion实现,关于DeviceMotion介绍可以查看
https://developer.mozilla.org/en-US/docs/Web/Reference/Events/devicemotion
通过DeviceMotionEvent,可以获得accelerationIncludingGravity的x,y,z属性,根据x,y,z属性的变化来判断设备是否有摇一摇的事件发生。
accelerationIncludeingGravity说明:
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.
代码如下:
版权声明:除特别声明外,本站所有文章皆是本站原创,转载请以超链接形式注明出处!