You are on page 1of 1

Background Slide Show

This JavaScript allows to show unlimited number of images in background of your


website with pre-determined interval.

Insert into <HEAD>


<style>
body{
/*Remove below line to make bgimage NOT fixed*/
background-attachment:fixed;
background-repeat: no-repeat;
/*Use center center in place of 300 200 to center bg image*/
background-position: 300 200;
}
</style>

<script language="JavaScript1.2">
var bgimages=new Array()
bgimages[0]="img1.jpg"
bgimages[1]="img2.jpg"
bgimages[2]="img3.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
document.body.background=pathToImg[inc].src
}

if (document.all||document.getElementById)
window.onload=new Function('setInterval("bgSlide()",3000)')

</script>

You might also like