【问题标题】:See progress of downloaded images of website?查看下载网站图片的进度?
【发布时间】:2012-11-12 13:37:30
【问题描述】:

我想看看图片的下载进度。

我有一张大图,我想看看该图片的下载情况如何,这可能吗?

【问题讨论】:

标签: javascript html


【解决方案1】:

here 已经讨论过一种使用 jQuery 插件的方法。

also a implementation 基于 'Content-Length' 响应头,但它在 IE 上不起作用,因为 IE 的 XHR 对象没有实现 readyState 3。

最后一种方法主要包括轮询 XHR 对象并询问它的长度以及已经下载的响应。您可能会适应使用下载图像,但同样,它不是浏览器证明的:

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);
    },

});

我希望它有所帮助。干杯

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-23
    • 1970-01-01
    相关资源
    最近更新 更多