gpt4 book ai didi

javascript - 如何识别图像何时用 jQuery 下载完成?

转载 作者:行者123 更新时间:2023-12-01 03:25:58 25 4
gpt4 key购买 nike

我正在使用表单输入来动态更改 img 标签的来源。我想用 ajax 加载程序代替图像,直到图像下载完成,然后用新图像替换加载程序。有人知道我该怎么做吗?

最佳答案

您不需要 jQuery 即可知道图像何时加载。

    // 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 在浏览器加载图像时调用,无论是从网络还是本地缓存加载图像。

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

关于javascript - 如何识别图像何时用 jQuery 下载完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5176289/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com