AmbientLightSensor: thuộc tính illuminance
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 illuminance của giao diện AmbientLightSensor 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ữ.
Giá trị
Một Number cho biết mức sáng hiện tại tính bằng lux.
Ví dụ
js
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-reading-attribute> |