Forked from mandymichael/ambient-light-simple-demo.js
Created
January 7, 2020 20:10
-
-
Save shopifypartners/edf26c2fd4365dbeeb4e1ffa286a4cde to your computer and use it in GitHub Desktop.
Simple Ambient Light Sensor Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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