Home > Web Front-end > H5 Tutorial > body text

How to implement the shake function through html5

jacklove
Release: 2018-06-09 10:04:08
Original
2490 people have browsed it

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实现摇一摇 
  
 
 
    

请执行摇一摇

Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!