Created
December 16, 2019 12:21
-
-
Save mandymichael/fef4a2677ec5ff9ac07b6af7e85cea3d 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