Skip to content

Instantly share code, notes, and snippets.

@amad
Created March 15, 2014 07:54
Show Gist options
  • Save amad/9563175 to your computer and use it in GitHub Desktop.
Save amad/9563175 to your computer and use it in GitHub Desktop.
window.addEventListener('devicelight', function(e) {
var lux = e.value;
document.querySelector('#result').textContent = lux + ' lux';
if(lux < 50) {
document.body.className = 'dim';
}
if(lux >= 50 && lux <= 1000) {
document.body.className = 'normal';
}
if(lux > 1000) {
document.body.className = 'bright';
}
});
window.addEventListener('lightlevel', function(e) {
var level = e.value; document.querySelector('#resultLevel').textContent = level;
if(level === 'dim') {
document.body.className = 'dim';
}
if(level === 'normal') {
document.body.className = 'normal';
}
if(level === 'bright') {
document.body.className = 'bright';
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment