Skip to content

Instantly share code, notes, and snippets.

@cferdinandi
Created June 26, 2018 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cferdinandi/63fbb04d18034319e25b25da403d9d2b to your computer and use it in GitHub Desktop.
Save cferdinandi/63fbb04d18034319e25b25da403d9d2b to your computer and use it in GitHub Desktop.
// Old-school ES5 way
function toggle () {
for (var i = 0; i < element.length; i++) {
if (element[i].style.opacity === '0') {
element[i].style.opacity = '1';
} else {
element[i].style.opacity = '0';
}
}
}
// Modern ES6 methods
// Include polyfill.io to ensure backwards compatibility
var elements = document.querySelectorAll('.robot');
setInterval(toggle, 800);
function toggle () {
Array.from(elements).forEach(function (element) {
if (element.style.opacity === '0') {
element.style.opacity = '1';
} else {
element.style.opacity = '0';
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment