Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Ambient Light Sensor Demo
if ( 'AmbientLightSensor' in window ) {
const sensor = new AmbientLightSensor();
sensor.onreading = () => {
if ( sensor.illuminance < 20) {
element.style.setProperty('--bg', 'black’);
} else {
element.style.setProperty('--bg', 'blue’);
}
};
sensor.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.