Sensor: sự kiện activate
Limited availability
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.
Sự kiện activate được kích hoạt khi cảm biến được kích hoạt, nghĩa là nó sẽ bắt đầu nhận dữ liệu đọc.
Giao diện Sensor là lớp cơ sở, onactivate và sự kiện activate chỉ có thể được sử dụng trên một trong các lớp dẫn xuất.
Cú pháp
Sử dụng tên sự kiện trong các phương thức như addEventListener(), hoặc đặt thuộc tính trình xử lý sự kiện.
js
addEventListener("activate", (event) => { })
onactivate = (event) => { }
Kiểu sự kiện
Một Event chung không có thuộc tính bổ sung.
Ví dụ
>Ghi log khi gia tốc kế sẵn sàng đo
Ví dụ này thêm trình lắng nghe sự kiện để ghi log việc kích hoạt của Accelerometer.
js
const acl = new Accelerometer({ frequency: 60 });
acl.addEventListener("activate", () => console.log("Ready to measure."));
acl.start();
Thông số kỹ thuật
| Specification |
|---|
| Generic Sensor API> # sensor-onactivate> |