BONUS: KnightRider-style oscillating action (otherwise same code):
<html>
<head>
<style type="text/css">
.color { height: 100px; width: 100px; float: left; margin-right: 5px; }
.red { background-color: red; }
.blue { background-color: blue; }
.yellow { background-color: yellow; }
.green { background-color: green; }
</style>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
var code = {
hiddenIndex : -1,
direction: 1,
showAll : function () {
$(".red").css("background-color","red");
$(".blue").css("background-color","blue");
$(".yellow").css("background-color","yellow");
$(".green").css("background-color","green");
},
hideOne : function (cssRef) {
code.showAll();
$(cssRef).css("background-color","white");
},
animate : function () {
switch(code.hiddenIndex) {
case -1:
code.showAll();
break;
case 0:
code.hideOne(".red");
break;
case 1:
code.hideOne(".blue");
break;
case 2:
code.hideOne(".yellow");
break;
case 3:
code.hideOne(".green");
break;
case 4:
code.showAll();
break;
}
code.hiddenIndex = code.hiddenIndex + code.direction;
if (code.hiddenIndex > 3 || code.hiddenIndex < 0) code.direction = code.direction * -1;
}
};
(function () {
window.setInterval(function () { code.animate(); }, 200);
})();
</script>
</head>
<body>
<div class="colors">
<div class="red color"></div>
<div class="blue color"></div>
<div class="yellow color"></div>
<div class="green color"></div>
</div>
</body>
</html>