仅当图像确实是第一次加载时才显示图像的加载 gif

发布于 2024-08-24 18:59:41 字数 457 浏览 6 评论 0原文

我有 2 个 img 元素。他们有 2 个 id:rimg 和 limg。 limg 是加载 gif,rimg 是重新加载的完整版本图像。

这是在图像完成加载之前显示加载的代码:

$("#limg").fadeIn("fast");
$("#rimg").attr("src",$(that).attr("bsrc")).load(function(){
    $("#limg").fadeOut("fast",function () {
        $("#rimg").attr("alt",$(that).attr("alt"));
        $("#rimg").fadeIn("normal");
});
});

如果我第一次登录该网站,它会显示加载 gif。 如果这不是我第一次,它仍然显示这一点,但我需要在没有加载的情况下加载顺利 在显示加载 gif 之前,如何检查图像是否已加载并缓存?

i have 2 img elements. 2 id's for them: rimg and limg.
limg is the loading gif and rimg is the reloaded full vertsion of the image.

the is the code to show the loading before image finish to load:

$("#limg").fadeIn("fast");
$("#rimg").attr("src",$(that).attr("bsrc")).load(function(){
    $("#limg").fadeOut("fast",function () {
        $("#rimg").attr("alt",$(that).attr("alt"));
        $("#rimg").fadeIn("normal");
});
});

if i log into the site for the first time, it shows me the loading gif.
if it is not my first time it is still showing that but i need the loading to be smooth without that loading
how can i check if the image is loaded and cached before showing the loading gif?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰つ倒转 2024-08-31 18:59:41

我认为这是您唯一的解决方案:如果您将以下内容构建到您的 jquery 脚本中,那么就可以工作。

var pic=new Image(x,y);//x,y is optional
pic.src= //path;

if(pic.complete) donePic()
else pic.onload= donePic;

如果您将其放入计时器中,那么您就会知道它何时加载。

I think this is the only solution for you: if you build the following into your jquery script then will work.

var pic=new Image(x,y);//x,y is optional
pic.src= //path;

if(pic.complete) donePic()
else pic.onload= donePic;

If you put it inside of a timer then you'll know when it gets loaded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文