JSFiddle - React, Tailwind, and code Playground
by alnitak
JavaScript
function colorCycle(el, count, cols) {
var i = 0,
n = cols.length;
el = (typeof el === "string") ? document.getElementById(el) : el;
(function repeat() {
var interval = cols[i][1];
el.style.background = cols[i][0];
if (++i === n) {
if (count && !--count) {
return;
} else {
i = 0;
}
}
setTimeout(repeat, interval);
})();
};
colorCycle(document.body, 5, [
['red', 1000],
['gold', 500]]);