gpt4 book ai didi

jquery - 加载图像后调用函数,如果加载图像也调用该函数

转载 作者:行者123 更新时间:2023-12-01 08:10:46 24 4
gpt4 key购买 nike

我使用此代码在加载图像后调用函数

var height = 0;
$("#right-layout-ul li img").on("load",function(){
function_function();
});

如果我刷新页面,该函数不会调用,因为图像已经加载...

有什么方法可以找到图像的状态,例如已加载或正在加载吗?

我想在图像加载后调用一个函数,如果图像加载也调用该函数...

如何实现???请帮助我

最佳答案

var $images = $("#right-layout-ul li img")
, imageCount = $images.length
, counter = 0;

// one instead of on, because it need only fire once per image
$images.one("load",function(){

// increment counter everytime an image finishes loading
counter++;
if (counter == imageCount) {

// do stuff when all have loaded
function_function();
}
}).each(function () {
if (this.complete) {

// manually trigger load event in
// event of a cache pull
$(this).trigger("load");
}
});

关于jquery - 加载图像后调用函数,如果加载图像也调用该函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13858250/

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