<legend id='3qbcE'><style id='3qbcE'><dir id='3qbcE'><q id='3qbcE'></q></dir></style></legend>

    <small id='3qbcE'></small><noframes id='3qbcE'>

  1. <tfoot id='3qbcE'></tfoot>
    • <bdo id='3qbcE'></bdo><ul id='3qbcE'></ul>
  2. <i id='3qbcE'><tr id='3qbcE'><dt id='3qbcE'><q id='3qbcE'><span id='3qbcE'><b id='3qbcE'><form id='3qbcE'><ins id='3qbcE'></ins><ul id='3qbcE'></ul><sub id='3qbcE'></sub></form><legend id='3qbcE'></legend><bdo id='3qbcE'><pre id='3qbcE'><center id='3qbcE'></center></pre></bdo></b><th id='3qbcE'></th></span></q></dt></tr></i><div id='3qbcE'><tfoot id='3qbcE'></tfoot><dl id='3qbcE'><fieldset id='3qbcE'></fieldset></dl></div>

    1. 如何监控图像源的满载状态

      时间:2023-10-13
    2. <small id='cKb9D'></small><noframes id='cKb9D'>

    3. <i id='cKb9D'><tr id='cKb9D'><dt id='cKb9D'><q id='cKb9D'><span id='cKb9D'><b id='cKb9D'><form id='cKb9D'><ins id='cKb9D'></ins><ul id='cKb9D'></ul><sub id='cKb9D'></sub></form><legend id='cKb9D'></legend><bdo id='cKb9D'><pre id='cKb9D'><center id='cKb9D'></center></pre></bdo></b><th id='cKb9D'></th></span></q></dt></tr></i><div id='cKb9D'><tfoot id='cKb9D'></tfoot><dl id='cKb9D'><fieldset id='cKb9D'></fieldset></dl></div>

      • <legend id='cKb9D'><style id='cKb9D'><dir id='cKb9D'><q id='cKb9D'></q></dir></style></legend>

            • <bdo id='cKb9D'></bdo><ul id='cKb9D'></ul>
                  <tbody id='cKb9D'></tbody>

                <tfoot id='cKb9D'></tfoot>
              1. 本文介绍了如何监控图像源的满载状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在将大量图像加载到动态 DIV 中,并且我正在使用预加载器来获取图像.

                I am loading a large number of images into a dynamic DIV and I am using a preloader to get the images.

                imageObj = new Image();
                imageObj.src = imgpath + imgname;
                

                这些事件中的每一个都会创建一个我可以在 Firebug 中查看和监控的 GET.

                Each of these events creates a GET that I can see and monitor in Firebug.

                如果我知道图片的名称和路径,我可以查看相关的 XMLHttpRequest 以查看 GET 是否完成?

                If I know the name and path of an image, can I watch the relevant XMLHttpRequest to see if the GET has completed?

                我不想为此过程依赖(或使用).onload 事件.

                I do not want to rely on (or use) .onload events for this process.

                伪代码看起来像这样......

                The pseudo would look something like this...

                if (imageObj.GET = 'complete')
                

                有人有这方面的经验吗?

                Has anyone had any experience of this?

                编辑 1

                感谢 Bart 的帮助(见下文),我已更改图像预加载器以存储图像对象数组...

                Thanks to the help from Bart (see below) I have changed my image preloader to store an array of the image objects...

                function imagePreLoader(imgname) {
                    images[imgnum] = new Image();
                    images[imgnum].src = imgpath + imgname;// load the image
                    imgnum ++;
                }
                

                然后,在我的所有其他函数都运行以构建内容 DIV 之后,我在下面使用了 image.complete 属性...

                And then, after all my other functions have run to build the content DIVs, I used the image.complete attribute in the following...

                var interval = setInterval(function () {
                    imgcount = imgnum - 1; // because the imgnum counter ++ after src is called.
                    ok = 1;
                
                    for (i=0; i<imgcount; i++) {
                        if (images[i].complete == false){
                            ok = 0;
                        }
                    }
                
                    if (ok == 1) {
                        clearInterval(interval);
                        showIndexOnLoad();
                    }
                }, 1000);
                

                这会等到所有图像都完成后,只有当我从间隔函数中得到ok"时才会触发 showIndexOnLoad() 函数.

                This waits until all the images are complete and only triggers the showIndexOnLoad() function when I get the 'ok' from the interval function.

                所有图像现在都如我所愿,一次全部显示,无需额外等待 GET 赶上.

                All images now appear as I wanted, all at once with no additional waits for the GETs to catch up.

                干得好 Bart 让我了解 image.complete 属性.p>

                Well done Bart for putting me on to the image.complete attribute.

                推荐答案

                可以观察图片的complete属性,看看图片是否加载完毕.

                You can watch the complete property of the image to see if the image is fully loaded or not.

                这是一个例子.

                http://jsfiddle.net/t3esV/1/

                function load (source) {
                    var img = new Image();
                    img.src = source;
                
                    console.log('Loading ' + source);
                
                    var interval = setInterval(function () {
                        if (img.complete) {
                            clearInterval(interval);
                            complete(img);
                        }
                    }, 400);
                };
                
                function complete(img) {
                    console.log('Loaded', img.src);
                    document.body.appendChild(img);
                };
                

                注意:当出现问题并且 complete 从未设置为 true 时,此示例无法清除间隔.

                Note: This example fails to clear the interval when something goes wrong and complete is never set to true.

                我写了一个简单的 jQuery.preload 插件来利用 图像.完整的 属性.

                I wrote a simple jQuery.preload plugin to take advantage of the image.complete property.

                这篇关于如何监控图像源的满载状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Google Chrome:当凭证标志为真时,不能在“Access-C 下一篇:Web 应用程序中的跨源请求

                相关文章

                最新文章

                <small id='RcTaZ'></small><noframes id='RcTaZ'>

                <i id='RcTaZ'><tr id='RcTaZ'><dt id='RcTaZ'><q id='RcTaZ'><span id='RcTaZ'><b id='RcTaZ'><form id='RcTaZ'><ins id='RcTaZ'></ins><ul id='RcTaZ'></ul><sub id='RcTaZ'></sub></form><legend id='RcTaZ'></legend><bdo id='RcTaZ'><pre id='RcTaZ'><center id='RcTaZ'></center></pre></bdo></b><th id='RcTaZ'></th></span></q></dt></tr></i><div id='RcTaZ'><tfoot id='RcTaZ'></tfoot><dl id='RcTaZ'><fieldset id='RcTaZ'></fieldset></dl></div>

              2. <legend id='RcTaZ'><style id='RcTaZ'><dir id='RcTaZ'><q id='RcTaZ'></q></dir></style></legend>
                  • <bdo id='RcTaZ'></bdo><ul id='RcTaZ'></ul>

                    <tfoot id='RcTaZ'></tfoot>