JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.container {
display: flex;
}
.color {
width: 100px;
height: 100px;
background: red;
border-radius: 50%;
margin-left: 20px;
}
.color_active {
width: 100px;
height: 100px;
background: blue;
border-radius: 50%;
margin-left: 20px;
}
</style>
<script>
window.addEventListener('DOMContentLoaded', change);
var color,
flag = 0;
function change() {
color = [...document.getElementsByClassName('color')];
setTimeout(act, 500);
}
function act() {
var lenCol = color.length;
if (flag < lenCol) {
color.filter((f => f.style.background = 'blue'))[flag];
console.log(color[flag]);
flag++;
} else {
[...color].forEach(her => her.style.background = 'green');
flag=0;
}
setTimeout(act, 500);
}
</script>
</head>
<body>
<div class='container'>
<div class="color"></div>
<div class="color"></div>
<div class="color"></div>
<div class="color"></div>
</div>
</body>
</html>