首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何识别使用jQuery完成图像下载的时间?

问如何识别使用jQuery完成图像下载的时间?
EN

Stack Overflow用户
提问于 2011-03-03 11:21:08
回答 2查看 191关注 0票数 2

我正在使用表单输入来动态更改img标记的源。我想将ajax加载器放在图像的位置,直到图像下载完成,然后用新的图像替换加载器。有人知道我是怎么做到的吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-03-03 11:29:14

您不需要jQuery就能知道图像是什么时候加载的。

代码语言:javascript
复制
    // show animation that indicates image is loading
    var test = new Image();
    test.onload = function () {
        // this gets called when the image has loaded
        // we need to place the image on the page:
        $('#ImageContainerWhatever').append(test);
        // and hide the loading animation
    };
    test.src = 'my_image.png';

onload是在浏览器加载图片时调用的,不管是从web还是本地缓存。

请看这些示例:https://developer.mozilla.org/en/Canvas_tutorial/Using_images

票数 2
EN

Stack Overflow用户

发布于 2011-03-03 11:22:29

您可以在镜像的load事件中添加事件监听器。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5176289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档