views:

32

answers:

1

I have an automatic slideshow on the main page of some site. Images are rotating every 10 seconds, but when they appear for the first time they aren't already loadead (I guess), so a blank is show.

I think that preloading these images they will show fine, but I don't know how to preload them. I use the following code to preload all the images of the page, but it doesn't seems to work:

function preloadAllImages() {
    for (i = 0; i < document.images; i++) {
        var img = new Image();
        img.src = document.images[i];
    }
}

So, how can I make this work?

A: 

Try

function preloadAllImages() {
    for ( var i = 0; i < document.images.length; i++) {
        var img = new Image();
        img.src = document.images[i];
    }
}

I believe you are missing the length attribute.

meder
Thanks for the help. I'll try this.
eKek0