An important feature of HTML5 is DeviceOrientation, which encapsulates the underlying direction sensor and motion sensor in advanced packaging and provides support for DOM events. This feature includes two events:
1. deviceOrientation: The event encapsulates the direction sensor data, and can obtain the direction data in the mobile phone's stationary state, such as the angle, orientation, orientation, etc. of the mobile phone.
2. deviceMotion: Events encapsulate motion sensor data, and can obtain data such as motion acceleration in the mobile phone's motion state. Using it we can easily achieve interesting functions such as gravity sensing and compass, which will be very useful on mobile phones. For example, the gravity sensing ball example in the Opera H5 trial version is achieved by monitoring deviceOrientation events of the DeviceOrientation API. In fact, it can also help us realize a very common and fashionable function in a mobile application on the web page: shake the mobile phone.
DeviceMotionEvent Returns the device's relevant information about acceleration and rotation. The acceleration data will contain three axes: x, y and z (schematically shown in the figure below, the x-axis penetrates the mobile phone screen or laptop keyboard horizontally, the y-axis runs the mobile phone screen or laptop keyboard vertically, and the z-axis is perpendicular to the mobile phone screen or laptop keyboard). Because some devices may not have hardware to exclude the impact of gravity, the event returns two properties, accelerationInclude Gravity and acceleration, which exclude the impact of gravity.
1. [Code] Monitoring motion sensing events
2. [Code] Get the acceleration with gravity
3. [Code] Core method to implement code
An important feature of HTML5 is DeviceOrientation, which encapsulates the underlying direction sensor and motion sensor in advanced packaging and provides support for DOM events. This feature includes two events:
1. deviceOrientation: The event encapsulates the direction sensor data, and can obtain the direction data in the mobile phone's stationary state, such as the angle, orientation, orientation, etc. of the mobile phone.
2. deviceMotion: Events encapsulate motion sensor data, and can obtain data such as motion acceleration in the mobile phone's motion state.
Using it we can easily achieve interesting functions such as gravity sensing and compass, which will be very useful on mobile phones. For example, the gravity sensing ball example in Opera H5 trial version is by monitoring DeviceOrientation
The deviceOrientation event of the API is implemented.
In fact, it can also help us realize a very common and fashionable function in a mobile application on the web page: shake the mobile phone.
DeviceMotionEvent Returns the device's relevant information about acceleration and rotation. The acceleration data will contain three axes: x, y and z (schematically shown in the figure below, the x-axis penetrates the mobile phone screen or laptop keyboard horizontally, the y-axis runs the mobile phone screen or laptop keyboard vertically, and the z-axis is perpendicular to the mobile phone screen or laptop keyboard). Because some devices may not have hardware to exclude the impact of gravity, the event returns two properties, accelerationInclude Gravity and acceleration, which exclude the impact of gravity.
1. [Code] Monitoring motion sensing events
Copy the code