var main = function() {
for (var i = 1; i <= 4; i++)
{
var time1 = 5000;
var time2 = 5500;
var location = "url('homepage/" + i + ".jpg')";
setTimeout(function() {
$('.jumbotron').fadeTo("slow", 0, function() { });
}, time1);
setTimeout(function() {
$('.jumbotron').css("background-image", location);
}, time2);
setTimeout(function() {
$('.jumbotron').fadeTo("slow", 1, function() { });
}, time2);
time1 += 5000;
time2 += 5000;
}
};
$(document).ready(main);
I'm trying to animate the changing of the background on a page. I have a folder with 4 pictures that I want the for to shuffle through. The problem is, with this code, the next image that fades in is the last one, aka the 4th one in this case, then it stops changing. I'm certainly doing something wrong.
time1 += 5000line is useless, because every next iteration you reset the times to their original values. Place the declarations of the time-vars outside the for-loop