how to load image in background?

对着背影说爱祢 提交于 2019-12-04 08:16:50

Just make a new image via javascript, and only show the image after the onload has fired. This will make sure you don't see any partial rendering of the image.

Live Demo

    var curImg = new Image();

    curImg.src = "url to your image";
    curImg.onload = function(){
        // do whatever here, add it to the background, append the image ect.
        imgHolder.appendChild(curImg);   
    }

You can play with 2 img tags. img1 shows the first image, while img2, is hidden, and loads the next image.

At the onload event of img2, you can hide img1, and show img2.

And load the next image with img1, and so on.

link rel="prerender" might do the trick.

http://www.catswhocode.com/blog/mastering-html5-prefetching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!