开发者

Automatic slideshow is not showing properly

开发者 https://www.devze.com 2022-12-08 22:47 出处:网络
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 alr开发者_如何学JAVAeady loadead (I guess), so a

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 alr开发者_如何学JAVAeady 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号