Fiddle here: http://jsfiddle.net/F6nJu/
I have a colored box:
#colorblock { background:#3ff; width: 100%; h
Array.prototype.recurse = function(callback, delay) {
delay = delay || 200;
var self = this, idx = 0;
setInterval(function() {
callback(self[idx], idx);
idx = (idx+1 < self.length) ? idx+1 : 0;
}, delay);
}
Try it on StackOverFlow:
["#f00", "#ff0", "#f0f", "#f66"].recurse(function(item, index) {
$('body').css('background-color', item);
}, 300);