Skip to content

Instantly share code, notes, and snippets.

@mandymichael
Created December 16, 2019 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mandymichael/fef4a2677ec5ff9ac07b6af7e85cea3d to your computer and use it in GitHub Desktop.
Save mandymichael/fef4a2677ec5ff9ac07b6af7e85cea3d to your computer and use it in GitHub Desktop.
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