Các tình nguyện viên của chúng tôi chưa dịch bài viết này thành Tiếng Việt. Tham gia với chúng tôi và hoàn thành công việc!
Bạn cũng có thể đọc bài viết trongEnglish (US).

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The DeviceMotionEvent provides web developers with information about the speed of changes for the device's position and orientation.

Warning: Currently, Firefox and Chrome do not handle the coordinates the same way. Take care about this while using them.

Constructor

DeviceMotionEvent.DeviceMotionEvent() 
Creates a new DeviceMotionEvent.

Properties

DeviceMotionEvent.accelerationRead only
An object giving the acceleration of the device on the three axis X, Y and Z. Acceleration is expressed in m/s2.
DeviceMotionEvent.accelerationIncludingGravityRead only
An object giving the acceleration of the device on the three axis X, Y and Z with the effect of gravity. Acceleration is expressed in m/s2.
DeviceMotionEvent.rotationRateRead only
An object giving the rate of change of the device's orientation on the three orientation axis alpha, beta and gamma. Rotation rate is expressed in degrees per seconds.
DeviceMotionEvent.intervalRead only
A number representing the interval of time, in milliseconds, at which data is obtained from the device.

Example

window.addEventListener('devicemotion', function(event) {
  console.log(event.acceleration.x + ' m/s2');
});

Specifications

Specification Status Comment
DeviceOrientation Event Specification
The definition of 'DeviceMotionEvent' in that specification.
Editor's Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
DeviceMotionEvent
Experimental
Chrome Full support YesEdge Full support YesFirefox Full support 6IE ? Opera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 6Opera Android No support NoSafari iOS Full support 4.2Samsung Internet Android Full support Yes
DeviceMotionEvent() constructor
ExperimentalNon-standard
Chrome Full support 59Edge ? Firefox ? IE ? Opera ? Safari ? WebView Android Full support 59Chrome Android Full support 59Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android ?
acceleration
Experimental
Chrome Full support YesEdge Full support 12Firefox Full support 6IE ? Opera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 6Opera Android No support NoSafari iOS Full support 4.2Samsung Internet Android Full support Yes
accelerationIncludingGravity
Experimental
Chrome Full support YesEdge Full support 12Firefox Full support 6IE ? Opera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 6Opera Android No support NoSafari iOS Full support 4.2Samsung Internet Android Full support Yes
interval
Experimental
Chrome Full support YesEdge Full support 12Firefox Full support 6IE ? Opera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 6Opera Android No support NoSafari iOS Full support 4.2Samsung Internet Android Full support Yes
rotationRate
Experimental
Chrome Full support YesEdge Full support 12Firefox Full support 6IE ? Opera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 6Opera Android No support NoSafari iOS Full support 4.2Samsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.

See also

Document Tags and Contributors

Cập nhật lần cuối bởi: ExE-Boss,