PDA

View Full Version : Background Image Slideshow- Delay before first slide/image appears



designbysjr
05-15-2009, 12:35 PM
Hi, I am a newbie to DD Forum but loving the javascripts. I have a problem with the Background Image Slideshow script.

(http://www.dynamicdrive.com/dynamicindex14/bgslide.htm)

It seems that the slide interval applies a delay on the first background image appearing. For example I set the var speed to 20000 to create a 20sec gap between slides, but the problem is when the page loads it waits 20sec before loading the first slide so I have a blank background. I want the page to have the first bg image as soon as it loads and then wait 20 secs before loading the next slide.

If I add a bg-image into the .body selector in the css this seems to override the javascript and stop the slideshow working.

Any ideas would be gratefully received!

Thanks

vwphillips
05-15-2009, 03:00 PM
//Background Image Slideshow- Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and TOS,
//visit http://www.dynamicdrive.com

//Specify background images to slide
var bgslides=new Array()
bgslides[0]="http://www.vicsjavascripts.org.uk/StdImages/Egypt8.jpg"
bgslides[1]="http://www.vicsjavascripts.org.uk/StdImages/Egypt9.jpg"
bgslides[2]="http://www.vicsjavascripts.org.uk/StdImages/Egypt10.jpg"

//Specify interval between slide (in miliseconds)
var speed=5000

//preload images
var processed=new Array()
for (i=0;i<bgslides.length;i++){
processed[i]=new Image()
processed[i].src=bgslides[i]
}

var inc=-1

function slideback(){
if (inc<bgslides.length-1)
inc++
else
inc=0
document.body.background=processed[inc].src
}

if (document.all||document.getElementById)
window.onload=function(){
slideback();
setInterval("slideback()",speed);
}