Accelerometer: thuộc tính z

Khả dụng hạn chế

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

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

Thuộc tính chỉ đọc z của giao diện Accelerometer trả về một số mô tả gia tốc của thiết bị theo trục z của nó.

Giá trị

Một Number.

Ví dụ

Gia tốc thường được đọc trong bộ gọi lại sự kiện reading. Trong ví dụ dưới đây, việc này xảy ra sáu mươi lần mỗi giây.

js
const accelerometer = new Accelerometer({ frequency: 60 });

accelerometer.addEventListener("reading", (e) => {
  console.log(`Gia tốc theo trục X ${accelerometer.x}`);
  console.log(`Gia tốc theo trục Y ${accelerometer.y}`);
  console.log(`Gia tốc theo trục Z ${accelerometer.z}`);
});
accelerometer.start();

Thông số kỹ thuật

Thông số kỹ thuật
Accelerometer
# accelerometer-z

Tương thích trình duyệt