aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/accelerometer/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/accelerometer/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/accelerometer/index.html')
-rw-r--r--files/zh-cn/web/api/accelerometer/index.html71
1 files changed, 71 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/accelerometer/index.html b/files/zh-cn/web/api/accelerometer/index.html
new file mode 100644
index 0000000000..51b5e7aa87
--- /dev/null
+++ b/files/zh-cn/web/api/accelerometer/index.html
@@ -0,0 +1,71 @@
+---
+title: Accelerometer
+slug: Web/API/Accelerometer
+translation_of: Web/API/Accelerometer
+---
+<div>{{APIRef("Generic Sensor API")}}</div>
+
+<p><span class="seoSummary">The <strong><code>Accelerometer</code></strong> interface of the <a href="/docs/Web/API/Sensor_APIs">Sensor APIs</a> provides on each reading the acceleration applied to the device along all three axes. </span></p>
+
+<p>To use this sensor, the user must grant permission to the <code>'accelerometer'</code>, device sensor through the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Permissions" title=""><code>Permissions</code></a> API.</p>
+
+<p>If a feature policy blocks the use of a feature, it is because your code is inconsistent with the policies set on your server. This is not something that would ever be shown to a user. See {{httpheader('Feature-Policy')}} for implementation instructions.</p>
+
+<h2 id="Constructor">Constructor</h2>
+
+<dl>
+ <dt>{{domxref("Accelerometer.Accelerometer()")}}</dt>
+ <dd>Creates a new <code>Accelerometer</code> object.</dd>
+</dl>
+
+<h2 id="Properties">Properties</h2>
+
+<dl>
+ <dt>{{domxref('Accelerometer.x')}} {{readonlyinline}}</dt>
+ <dd>Returns a double containing the acceleration of the device along the device's x axis.</dd>
+ <dt>{{domxref('Accelerometer.y')}} {{readonlyinline}}</dt>
+ <dd>Returns a double containing the acceleration of the device along the device's y axis.</dd>
+ <dt>{{domxref('Accelerometer.z')}} {{readonlyinline}}</dt>
+ <dd>Returns a double containing the acceleration of the device along the device's z axis.</dd>
+</dl>
+
+<h2 id="Example">Example</h2>
+
+<p>Acceleration is typically read in the {{domxref('Sensor.onreading')}} event callback. In the example below this occurs sixty times a second.</p>
+
+<pre class="brush: js">let accelerometer = new Accelerometer({frequency: 60});
+
+accelerometer.addEventListener('reading', e =&gt; {
+  console.log("Acceleration along the X-axis " + accelerometer.x);
+  console.log("Acceleration along the Y-axis " + accelerometer.y);
+  console.log("Acceleration along the Z-axis " + accelerometer.z);
+});
+accelerometer.start();</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Generic Sensor')}}</td>
+ <td>{{Spec2('Generic Sensor')}}</td>
+ <td>Defines sensors in general.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('Accelerometer','#accelerometer-interface','Accelerometer')}}</td>
+ <td>{{Spec2('Accelerometer')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("api.Accelerometer")}}</p>