简体   繁体   English

看到网站下载图像的进度了吗?

[英]See progress of downloaded images of website?

I want to see how far the download of an image has come. 我想看看下载图像的距离。

I have a big image that is sprited, and I want to see how the download of that image goes, is that even possible? 我有一个放大的图像,我想看看该图像的下载情况如何,那有可能吗?

There's a method already discussed here which uses a jQuery plugin. 这里已经讨论一种使用jQuery插件的方法。

There's also a implementation based on the 'Content-Length' response header, but it doesn't work on IE since the XHR object of IE doesn't implement readyState 3. 还有一个基于“ Content-Length”响应标头的实现,但由于IE的XHR对象未实现readyState 3,因此它不适用于IE。

The last approach consists essentially from polling the XHR object and ask it's length as well as the response already downloaded. 最后一种方法实质上是通过轮询XHR对象并询问其长度以及已下载的响应来完成的。 You may adapt to use downloading an image, but again, it's not browser-proof: 您可以适应使用下载图像,但是同样,它不是浏览器认证的:

var myTrigger;
var progressElem = $('#progressCounter');

$.ajax ({
    beforeSend: function (thisXHR)
    {
            myTrigger = setInterval (function ()
            {
                    if (thisXHR.readyState > 2)
                    {
                            var totalBytes  = thisXHR.getResponseHeader('Content-length');
                            var dlBytes     = thisXHR.responseText.length;
                            (totalBytes > 0)? progressElem.html (Math.round ((dlBytes/totalBytes) * 100) +"%"):progressElem.html (Math.round (dlBytes /1024) + "K");
                    }
            }, 200);
    },

});

I hope it helped. 希望对您有所帮助。 Cheers 干杯

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

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