sniperman
09-03-2009, 10:46 AM
Hi everyone. I have a background image rotator script to change the background image on intervals. The only problem is that the image paths stored in the array fail to be called properly in the script. Can anyone tell me whether the method for calling the array is correct because i placed the array's string directly into the backgroundImage = value and that works fine.
images = new Array();
images[0] = "images/one.gif";
images[1] = "images/two.gif";
images[2] = "images/three.gif";
images[3] = "images/four.gif";
images[4] = "images/five.gif";
images[5] = "images/six.gif";
images[6] = "images/seven.gif";
images[7] = "images/eight.gif";
window.onload = function showDelay() {
setInterval ("changeBg('footer');", 5000);
}
var ns = (document.all)?false:true;
var intBack = 1;
i=0;
//function for dynamically switching the background image
function changeBg(divId) {
if (ns){
layerObject = document.getElementById(divId).style;
} else {
layerObject = eval(divId + ".style");
}
if (i==8) {i=0;}
layerObject.backgroundImage = 'url(images[i])';
i++;
}
images = new Array();
images[0] = "images/one.gif";
images[1] = "images/two.gif";
images[2] = "images/three.gif";
images[3] = "images/four.gif";
images[4] = "images/five.gif";
images[5] = "images/six.gif";
images[6] = "images/seven.gif";
images[7] = "images/eight.gif";
window.onload = function showDelay() {
setInterval ("changeBg('footer');", 5000);
}
var ns = (document.all)?false:true;
var intBack = 1;
i=0;
//function for dynamically switching the background image
function changeBg(divId) {
if (ns){
layerObject = document.getElementById(divId).style;
} else {
layerObject = eval(divId + ".style");
}
if (i==8) {i=0;}
layerObject.backgroundImage = 'url(images[i])';
i++;
}