Each time the function is called i is set to 0 then it loops through all the images.
You redefine the array on each call as well, very wasteful of client resources
It should increment the counter, check for it being greater that the array size then set to 0 if it is.
Then set the image from the array.
so
set the array and counter as global
increment the count on each timeout and change the image.
Code:
var timeRefresh = setInterval("bannerChange()", 1000);
var i = 0;
var bannerImage = new Array();
bannerImage[0] = "../images/banner1.png"
bannerImage[1] = "../images/banner2.png"
bannerImage[2] = "../images/banner3.png"
bannerImage[3] = "../images/banner4.png"
function bannerChange() {
i++
if (i > bannerImage.Length) {
i = 0
}
document.getElementById('banner').style.backgroundImage = "url(bannerImage[i])";
}
Not tested BTW looks OK though.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
|