Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shopifypartners/b2cad5708719ed0cbac26eb7d3c91011 to your computer and use it in GitHub Desktop.
Save shopifypartners/b2cad5708719ed0cbac26eb7d3c91011 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