Magnetometer: y property

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 y của giao diện Magnetometer trả về một số xác định từ trường xung quanh trục y của thiết bị.

Giá trị

Một Number.

Ví dụ

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

js
let magSensor = new Magnetometer({ frequency: 60 });

magSensor.addEventListener("reading", (e) => {
  console.log(`Magnetic field along the X-axis ${magSensor.x}`);
  console.log(`Magnetic field along the Y-axis ${magSensor.y}`);
  console.log(`Magnetic field along the Z-axis ${magSensor.z}`);
});
magSensor.start();

Thông số kỹ thuật

Thông số kỹ thuật
Magnetometer
# magnetometer-y

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