I want to cycle through a bunch of jpg pictures as a slideshow. I have been using setInterval with success so far. However, I now want to have each slide show for a custom time. For example slide 1 shows for 6 seconds, then slide 2 for 3 seconds, etc. I tried the following code:
var sl = [["PodLoop1.jpg", 6000], ["PodLoop2.jpg", 3000]];
$.each(sl, function(i, value) {
fl = '<img src="media/' + value[0] + '" height="100%">'
setTimeout(function(){
$("#InnerMedia").html(fl);
if (i >= sl.length) {
window.location.href = "./media.php"; // refresh to restart from the beginning
}
}, value[1])
});
But this doesn't work. It just jumps to the last slide in the list. What am I doing wrong? I have looked at several similar questions on SO, for example this one, but none of them seem to deal with a variable timer.