jsBin demo

I would do this using an absolute located DIV superimposed on the body . Replace in the DIV new image, then set the same image to body and hide the DIV as follows: (GRAY - body , SOrange - DIV )

The increment of the current array of images is achieved by preliminary specifying ++counter .
Loop locking is achieved using the Remainder % operator to prevent the number of counters in the array from being exceeded.
The loop itself is executed inside the .fadeTo() callback function, just do a new iteration of the loopBg() function.
This is the necessary CSS:
*{margin:0;padding:0;} html, body{height:100%;width:100%;} body, #bg{ background: #000 none 50% / cover; } #bg{ position:absolute; top:0; bottom:0; left:0; right:0; width:100%; height:100%; }
And jQ:
var images = [ "bg0.jpg", "bg1.jpg", "bg2.jpg" ]; var $body = $("body"), $bg = $("#bg"), n = images.length, c = 0; // Loop Counter // Preload Array of images... for(var i=0; i<n; i++){ var tImg = new Image(); tImg.src = images[i]; } $body.css({backgroundImage : "url("+images[c]+")"}); (function loopBg(){ $bg.hide().css({backgroundImage : "url("+images[++c%n]+")"}).delay(2000).fadeTo(1200, 1, function(){ $body.css({backgroundImage : "url("+images[c%n]+")"}); loopBg(); }); }());
Edit: If you want the background to change but scrollable content, just add overflow:auto; on #page , as in this demo: http://jsbin.com/huzayiruti/1/
source share