Use setinterval with a callback that changes the background:
$("document").ready(function() { var colours = [ "blue", "orange", "pink" ]; var counter = 0; function cycleBackground() { $("body").animate({ backgroundColor: colours[counter] }, 500 ); counter++; if(counter == colours.length) { counter = 0; } } setInterval(cycleBackground, 10000); });
You will need to use the jQuery UI animate function if you want to seamlessly switch between colors.
source share