gpt4 book ai didi

jquery - 检查图像是否已使用 jQuery 缓存

转载 作者:行者123 更新时间:2023-12-01 00:16:14 24 4
gpt4 key购买 nike

我需要向图像添加 .load 函数,但是,如果图像已缓存,我不希望添加此函数,主要是因为在该 .load 函数中我淡入图像并隐藏加载指示器。

如果图像已经缓存,我不需要这些。有没有办法检查它是否在缓存中?

谢谢,韦斯利

最佳答案

我很高兴不久前有人提出这个问题,但我一直在寻求解决同样的问题,如果其他人遇到这个问题,以下是我的解决方法。

我使用了一个延迟 200 毫秒的 window.setTimeout() 来调用我的预加载器效果,并且在正在加载的图像的 .load() 事件中,它所做的第一件事就是清除超时,因此如果加载速度很快- 不显示任何效果,但如果图像加载时间超过 200 毫秒,则会显示预加载器:

var imgTmr;

imgTmr = window.setTimeout(function() {showLoading('zoomImage');}, 200);

$("#zoomImage").load(function() {
window.clearTimeout(imgTmr);
hideLoading();
}

$("#zoomImage").attr("src", "myLargeImage.jpg");

// The showLoading() and hideLoading() functions just display a wait graphic
// the image being loaded in this instance has the id of zoomImage

关于jquery - 检查图像是否已使用 jQuery 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7096974/

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