小编给大家分享一下通过html5实现摇一摇的功能的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!
原理:使用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.
代码如下:
html5使用DeviceMotionEvent实现摇一摇 请执行摇一摇
看完了这篇文章,相信你对通过html5实现摇一摇的功能的方法有了一定的了解,想了解更多相关知识,欢迎关注创新互联网站制作公司行业资讯频道,感谢各位的阅读!