简体   繁体   English

如何预加载一组图像,然后开始图像幻灯片播放?

[英]How to preload a set of images and then start the image slideshow?

I'm creating a slideshow with 5 frames (each of which will have its own slideshow of images) with huge images and it takes some time for the first few images in each frame to be loaded(the rest of the images are loaded really fast). 我正在创建一个包含5帧(每个幻灯片都有自己的图像幻灯片)的幻灯片,其中包含巨大的图像,并且要花一些时间才能加载每帧中的前几幅图像(其余图像的加载速度非常快) )。 So I was thinking I could preload a simple black images (the background is black) and then start my slideshow once I know the images have loaded. 所以我想我可以预加载一个简单的黑色图像(背景为黑色),然后在知道图像已加载后开始幻灯片播放。 Also, the slideshow images are dynamic, ie their urls change every day. 另外,幻灯片图像是动态的,即其网址每天都在变化。

Does anyone know how I could do that? 有人知道我该怎么做吗? Because what I've found online only preloads an image but says nothing about how to start my slideshow after that. 因为我在网上找到的东西只能预加载图像,但是此后如何开始幻灯片放映却什么也没说。

Or if anyone has a better solution, please let me know! 或者,如果有人有更好的解决方案,请告诉我!

FYI, for the slideshow I've used PHP to extract the image urls into a file and JavaScript to read them from it and display them in the slideshow. 仅供参考,对于幻灯片,我已经使用PHP将图像网址提取到文件中,并使用JavaScript从文件中读取它们并在幻灯片中显示它们。

Thanks! 谢谢!

A good way to preload images is to load them outside of the frame using css with position: absolute, i can remember reading that using display: none; 预加载图像的一种好方法是使用位置为:绝对的css将图像加载到框架之外。我还记得使用display:none;读取过的图像。 it would not get downloaded by Safari. Safari不会下载它。

This seems to be an elegant way to precache the images. 这似乎是预缓存图像的一种优雅方法。

"Per Paul Irish, the canonical plugin for detecting image load complete events is now at: “根据Paul Irish, 用于检测图像加载完成事件规范插件现在位于:

https://github.com/desandro/imagesloaded " https://github.com/desandro/imagesloaded

Source: jQuery event for images loaded 来源:已加载图像的jQuery事件

This should work 这应该工作

/*You could populate this array through an xml to something if there are too many images*/
var arrUrls = ["image1.jpg", "image2.jpg", "image3.jpg"];
var nLoadCount = 0;
for(var i=0;i<arrUrls.length;i++)
{
    var oImage = new Image ();
    oImage.onload = function ()
    {
        nLoadCount++;
        if(nLoadCount == arrUrls.length)
        {
            /*Show your content here*/
        }
    }
    oImage.src = arrUrls[i];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM