slideshow for div's background image + jquery

designer-trying-coding picture designer-trying-coding · Sep 22, 2009 · Viewed 17.7k times · Source

I have a big div element at header and there are many text contents and some boxes in the div. and i have a big img as bg for this div, now i need to make a slideshow for this div's background :/

How can I make slideshow for a div's background image?

I researched a lot, but could not find anything :/

Thanks a lot! appreciate!

Answer

peirix picture peirix · Sep 22, 2009

One way of doing this is to make an array of background-images:

var bgArr = ["img/bg1.jpg", "img/bg2.jpg"]; //and so on...
function backgroundSlide(i) {
    $("#header").css("background-image", "url("+bgArr[i++]+")");
    if (i == bgArr.length) i = 0;
    var st = setTimeout(arguments.callee(i), 1000);
}
backgroundSlide(0)

This will just loop and loop...