Created
June 26, 2018 00:28
-
-
Save cferdinandi/63fbb04d18034319e25b25da403d9d2b to your computer and use it in GitHub Desktop.
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
// 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