jQuery: infinite loop through array… each()?

前端 未结 4 1494
攒了一身酷
攒了一身酷 2021-01-06 06:16

Fiddle here: http://jsfiddle.net/F6nJu/

I have a colored box:

#colorblock { background:#3ff; width: 100%; h
4条回答
  •  一整个雨季
    2021-01-06 06:49

    var arr = ["#f00", "#ff0", "#f0f", "#f66"];
    
    (function recurse(counter) {
        var arrLength = arr.length;
        var index = counter%arrLength;
    
        var color = arr[index];
    
        $('#colorblock').delay('1200').animate({
           backgroundColor: color
         }, 600);
    
        setTimeout(function() {
           recurse(counter + 1);
        }, 200);
    
    })(0);
    

提交回复
热议问题