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