Last active
October 30, 2016 16:02
-
-
Save Fabiantjoeaon/1c3d7fd00198d5d6cb74e7c57de45b81 to your computer and use it in GitHub Desktop.
Useful HTML5 Web API uses, most change in the future, and have limited browser support, so be sure to look these up before implementing them. src: https://www.youtube.com/watch?v=NCGLPp778JY
This file contains hidden or 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
// Listen for ambient lighting in room | |
window.addEventListener('devicelight', (e) => { | |
console.log(`${e.value} lux`); | |
}); |
This file contains hidden or 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
// Check battery status of device through the browser | |
navigator.getBattery().then((battery) => { | |
console.log(`${battery.level * 100}%`); | |
battery.addEventListener('levelchange', () => { | |
console.log(`${this.level * 100}%`); | |
}); | |
}); |
This file contains hidden or 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
// Listen for device orientatin | |
window.addEventListener('deviceorientation', (e) => { | |
console.log('Gamma: ', e.gamma); | |
console.log('Beta: ', e.beta); | |
console.log('Gamma: ', e.alpha); | |
}); |
This file contains hidden or 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
// Check if user is online of offline | |
console.log(navigator.onLine ? 'online' : 'offline'); |
This file contains hidden or 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
// Event listener switch for visible tab using Page Visibility | |
window.addEventListener('visibilitychange', () => { | |
switch(document.visibilityState) { | |
case 'prerender': | |
console.log('Tab is pre-rendering'); | |
break; | |
case 'hidden': | |
console.log('Tab is hidden'); | |
break; | |
case 'visible': | |
console.log('Tab is focused'); | |
break; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment