JayC
Always Learning
Okay so this codes purpose is to create an array that gets all my images I want the background to change every 4500 which follows another thing on my webpage.. My problem is I don't want the whole document body to change the background I just want one div box to change:
The div box I want to change is : cntbody
These were the 2 things I tried:
This one didn't do shit
document.getElementById("cntbody").style.backgroundImage = "url('pathToImg[inc].src')";
This one did the whole background
document.body.background=pathToImg[inc].src
Got it nevermind:
document.getElementById("cntbody").style.backgroundImage = "url('"+pathToImg[inc].src+"')";
Fuck life, thanks anyway
The div box I want to change is : cntbody
Code:
<script language="JavaScript1.2">
var bgimages=new Array()
bgimages[0]="background/1.jpg"
bgimages[1]="background/2.jpg"
bgimages[2]="background/3.jpg"
bgimages[3]="background/4.jpg"
//preload images
var pathToImg=new Array()
for (i=0;i<bgimages.length;i++){
pathToImg[i]=new Image()
pathToImg[i].src=bgimages[i]
}
var inc=-1
function bgSlide(){
if (inc<bgimages.length-1)
inc++
else
inc=0
***NEED TO POST IMAGE HERE USING THE ARRAY* pathToImg[inc].src
}
if (document.all||document.getElementById)
window.onload=new Function('setInterval("bgSlide()",4500)')
</script>
This one didn't do shit
document.getElementById("cntbody").style.backgroundImage = "url('pathToImg[inc].src')";
This one did the whole background
document.body.background=pathToImg[inc].src
Got it nevermind:
document.getElementById("cntbody").style.backgroundImage = "url('"+pathToImg[inc].src+"')";
Fuck life, thanks anyway