Sensor: reading イベント
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
reading
イベントは、センサーで新しい測定値が得られたとき発火します。
Sensor
はベースクラスであり、onreading
および reading
イベントは派生クラスからのみ利用可能です。
構文
addEventListener()
のようなメソッドでイベント名を用いるか、イベントハンドラープロパティを設定します。
js
addEventListener("reading", (event) => {});
onreading = (event) => {};
イベント型
汎用の Event
であり、追加されたプロパティはありません。
例
加速度を取得する
この例では、Accelerometer
から加速度の値を取得するイベントリスナーを追加します。1 秒に 60 回取得を行います。
js
const acl = new Accelerometer({ frequency: 60 });
acl.addEventListener("reading", () => {
console.log(`X 軸方向の加速度 ${acl.x}`);
console.log(`Y 軸方向の加速度 ${acl.y}`);
console.log(`Z 軸方向の加速度 ${acl.z}`);
});
acl.start();
仕様書
Specification |
---|
Generic Sensor API # sensor-onreading |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
reading event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.