Skip to content

Instantly share code, notes, and snippets.

@cmditch
Created April 7, 2020 06:05
Show Gist options
  • Save cmditch/2ea8f733dbd0aa93b86ebb58117c7b3c to your computer and use it in GitHub Desktop.
Save cmditch/2ea8f733dbd0aa93b86ebb58117c7b3c to your computer and use it in GitHub Desktop.
Javascript, the language of the browser first and foremost
function funTimes() {
let elements = document.getElementsByTagName('p');
let counter = 0;
setInterval(function() {
for (let i = 0; i < elements.length; i++) {
generateRainbowText(elements[i], counter);
}
counter++;
}, 200)
}
function generateRainbowText(element, counter) {
var text = element.innerText;
element.innerHTML = "";
for (let i = 0; i < text.length; i++) {
let charElem = document.createElement("span");
charElem.style.color = "hsl(" + (360 * i * ((counter % 12) + 1 ) / text.length) + ",80%,50%)";
charElem.innerHTML = text[i];
element.appendChild(charElem);
}
}
// Call forth the fun times!
funTimes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment