Ich möchte zwischen einem Array von Hintergrundfarben animieren.jQuery Hintergrundfarbe animieren. Remove Math.random
Ich fand den folgenden Code, aber es verwendet Math.random, um die Hintergrundfarben in zufälliger Reihenfolge anzuzeigen.
$(document).ready(function() {
setInterval(function() {
var theColours = Array('#ffffff','#000000','#00ff00','#ff0000','#0000ff');
var theColour = theColours[Math.floor(Math.random()*theColours.length)];
$('#branding').animate({backgroundColor: theColour}, 500);
}, 1000);
});
Ich möchte die Math.random und die nächste Farbe in der Matrix entfernen.
Wenn ich jedoch Math.random mit dem folgenden ersetzen, wird die Animation nicht über die erste Farbe im Array fortgesetzt.
$(document).ready(function() {
setInterval(function() {
var theColours = Array('#ffffff','#000000','#00ff00','#ff0000','#0000ff');
var currentColour = 0;
var theColour = theColours[Math.floor(currentColour++ % theColours.length)];
$('#branding').animate({backgroundColor: theColour}, 500);
}, 1000);
});