aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/devicemotionevent/index.html
blob: c0a4d3868c0f91e9d8478765b90c9e6545691d6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
title: DeviceMotionEvent
slug: Web/API/DeviceMotionEvent
tags:
  - API
  - DeviceMotionEvent
  - 传感器
  - 参考
  - 实验性
  - 接口
  - 移动设备
  - 运动传感器
translation_of: Web/API/DeviceMotionEvent
---
<p>{{apiref("Device Orientation Events")}}{{SeeCompatTable}}</p>

<p><code>DeviceMotionEvent</code> 为web开发者提供了关于设备的位置和方向的改变速度的信息。</p>

<div class="warning">
<p><strong>警告:</strong>目前,Firefox 和 Chrome 处理坐标的方式不同。 使用时要多加注意。</p>
</div>

<h2 id="构造函数">构造函数</h2>

<dl>
 <dt>{{DOMxRef("DeviceMotionEvent.DeviceMotionEvent()")}} {{Non-standard_Inline}}</dt>
 <dd>创建一个新的 <code>DeviceMotionEvent</code></dd>
</dl>

<h2 id="属性">属性</h2>

<dl>
 <dt>{{domxref("DeviceMotionEvent.acceleration")}} {{readonlyinline}}</dt>
 <dd>提供了设备在X,Y,Z轴方向上加速度的对象。加速度的单位为 <a href="https://en.wikipedia.org/wiki/Meter_per_second_squared" title="https://en.wikipedia.org/wiki/Meter_per_second_squared">m/s<sup>2</sup></a></dd>
 <dt>{{domxref("DeviceMotionEvent.accelerationIncludingGravity")}} {{readonlyinline}}</dt>
 <dd>提供了设备在X,Y,Z轴方向上带重力的加速度的对象。加速度的单位为 <a href="https://en.wikipedia.org/wiki/Meter_per_second_squared" title="https://en.wikipedia.org/wiki/Meter_per_second_squared">m/s<sup>2</sup></a></dd>
 <dt>{{domxref("DeviceMotionEvent.rotationRate")}} {{readonlyinline}}</dt>
 <dd>提供了设备在 alpha,beta, gamma轴方向上旋转的速率的对象。旋转速率的单位为度每秒。</dd>
 <dt>{{domxref("DeviceMotionEvent.interval")}} {{readonlyinline}}</dt>
 <dd>表示从设备获取数据的间隔时间,单位是毫秒。</dd>
</dl>

<h2 id="示例">示例</h2>

<pre class="brush: js">window.addEventListener('devicemotion', function(event) {
  console.log(event.acceleration.x + ' m/s2');
});</pre>

<h2 id="规范">规范</h2>

<table>
 <thead>
  <tr>
   <th scope="col"><strong>规范</strong></th>
   <th scope="col"><strong>状态</strong></th>
   <th scope="col"><strong>注释</strong></th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("Device Orientation", "#devicemotionevent", "DeviceMotionEvent")}}</td>
   <td>{{Spec2("Device Orientation")}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p>{{Compat("api.DeviceMotionEvent")}}</p>

<h2 id="参见">参见</h2>

<ul>
 <li>{{Event("deviceorientation")}}</li>
 <li>{{DOMxRef("DeviceOrientationEvent")}}</li>
 <li>{{Event("devicemotion")}}</li>
 <li><a href="https://wiki.developer.mozilla.org/en-US/docs/WebAPI/Detecting_device_orientation" title="/en-US/docs/WebAPI/Detecting_device_orientation">Detecting device orientation</a></li>
 <li><a href="https://developer.mozilla.org/en/DOM/Orientation_and_motion_data_explained" title="Orientation and motion data explained">Orientation and motion data explained</a></li>
</ul>