Created
January 26, 2015 00:16
-
-
Save banjeremy/1b3e2920995c972eda7a to your computer and use it in GitHub Desktop.
Firefox Light Sensor Events
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
<style> | |
.darklight { | |
background-color: #000; | |
color: #fff; | |
} | |
.brightlight { | |
background-color: #fff; | |
color: #000; | |
} | |
</style> | |
</head> | |
<body> | |
<h1 id="text"></h1> | |
<script> | |
window.addEventListener('devicelight', function(event) { | |
var html = document.getElementsByTagName('html')[0]; | |
document.getElementById("text").innerHTML = event.value; | |
if (event.value < 50) { | |
html.classList.add('darklight'); | |
html.classList.remove('brightlight'); | |
} else { | |
html.classList.add('brightlight'); | |
html.classList.remove('darklight'); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment