AmbientLightSensor
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.
Giao diện AmbientLightSensor của Sensor APIs trả về mức sáng hiện tại, hay độ rọi, của ánh sáng xung quanh thiết bị đang lưu trữ.
Để dùng cảm biến này, người dùng phải cấp quyền cho cảm biến thiết bị 'ambient-light-sensor' thông qua Permissions API.
Tính năng này có thể bị chặn bởi một Permissions Policy được đặt trên máy chủ của bạn.
Bộ khởi tạo
AmbientLightSensor()Thử nghiệm-
Tạo một đối tượng
AmbientLightSensormới.
Thuộc tính thể hiện
AmbientLightSensor.illuminanceRead only Thử nghiệm-
Trả về mức sáng hiện tại tính bằng lux của ánh sáng xung quanh thiết bị đang lưu trữ.
Phương thức thể hiện
AmbientLightSensor không có phương thức riêng. Tuy nhiên, nó kế thừa các phương thức từ các giao diện cha là Sensor và EventTarget.
Sự kiện
AmbientLightSensor không có sự kiện riêng. Tuy nhiên, nó kế thừa các sự kiện từ giao diện cha là Sensor.
Ví dụ
if ("AmbientLightSensor" in window) {
const sensor = new AmbientLightSensor();
sensor.addEventListener("reading", (event) => {
console.log("Current light level:", sensor.illuminance);
});
sensor.addEventListener("error", (event) => {
console.log(event.error.name, event.error.message);
});
sensor.start();
}
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| Ambient Light Sensor> # ambient-light-sensor-interface> |