AmbientLightSensor:illuminance 属性
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
AmbientLightSensor 接口的 illuminance 只读属性返回宿主设备周围环境光的当前光照强度,单位为 lux(勒克斯)。
值
一个 Number,表示当前的光照强度,单位为勒克斯(lux)。
示例
js
if ("AmbientLightSensor" in window) {
const sensor = new AmbientLightSensor();
sensor.addEventListener("reading", (event) => {
console.log("当前光照强度:", sensor.illuminance);
});
sensor.addEventListener("error", (event) => {
console.log(event.error.name, event.error.message);
});
sensor.start();
}
规范
| Specification |
|---|
| Ambient Light Sensor> # ambient-light-sensor-reading-attribute> |
浏览器兼容性
Loading…