gpt4 book ai didi

Jquery img on.load 仅在硬刷新页面时有效

转载 作者:行者123 更新时间:2023-12-01 07:41:19 24 4
gpt4 key购买 nike

我有一些加载文本,仅当图像已加载到页面上时,我才想将其替换为按钮。

我正在使用on.load,如下所示:

$('img.house').on('load', function() {
$('.loading').hide();
$('#startgame').show();
});

当我第一次访问该网站时,这非常有用,但当我刷新页面时,它不会隐藏 .loading div。

如果我然后在页面上进行硬刷新,它就会起作用......

有人可以帮我吗?

最佳答案

Jquery 的 .load 有一些警告,您可以在此处看到:https://api.jquery.com/load-event/

重要的一点在这里:

Can cease to fire for images that already live in the browser's cache

查看此线程,了解有人试图解决您遇到的确切问题的另一种可能的解决方案:jQuery callback on image load (even when the image is cached)

编辑:很好,有一个插件可以解决小不一致问题:https://github.com/desandro/imagesloaded

关于Jquery img on.load 仅在硬刷新页面时有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47777959/

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