AmbientLightSensor: illuminance property

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

{{securecontext_header}}{{APIRef("Sensor API")}}{{SeeCompatTable}}

The **illuminance** read-only property of the {{domxref("AmbientLightSensor")}} interface returns the current light level in lux of the ambient light level around the hosting device.

Value

A {{jsxref('Number')}} indicating the current light level in lux.

Examples

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();
}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}