Skip to content

Instantly share code, notes, and snippets.

@vrcosta
vrcosta / hardwareacceleratedcss.css
Created January 30, 2017 17:56
hardwareacceleratedcss.css
.accelerated {
-webkit-transform: translate3d(0,0,0);
-moz-transform: translate3d(0,0,0);
-ms-transform: translate3d(0,0,0);
-o-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
var webcamStream = null,
video = document.getElementById('player');
// try go get them all
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
document.getElementById('play').addEventListener('click', function(e) {
navigator.getUserMedia({
video: true
},
<button id="play">Capture webcam</button>
<button id="stop">Freeze image</button>
<video id="player"></video>
// Check the browser capabilities
if ('getBattery' in navigator) {
navigator.getBattery().then(initBatteryListeners);
} else {
document.getElementById('content').innerHTML = 'Your browser doesn\'t support the Battery API. Try Chrome or Firefox.';
}
// Callback when getting the battery
function initBatteryListeners(battery) {
updateInterface(battery);
window.addEventListener('devicelight', function(e) {
var html = document.querySelector('html');
if (e.value < 100) {
html.classList.remove('light');
html.classList.add('dark');
} else {
html.classList.remove('dark');
html.classList.add('light');
}
@vrcosta
vrcosta / pagevisibility.js
Last active December 29, 2016 22:08
PageVisibility API
document.addEventListener('visibilitychange', function(e) {
document.title = "vascocosta.net | " + document.visibilityState;
if (document.visibilityState === "visible") {
startXHR();
} else {
stopXHR();
}
});