我正在使用此代码在加载图像后调用函数
var height = 0;
$("#right-layout-ul li img").on("load",function(){
function_function();
});
如果我正在刷新页面,则该函数不会调用,因为图像已经加载...
有没有办法找到像加载或加载的图像状态?
我想在加载图像后调用一个函数,如果图像加载也调用函数...
如何实施???请帮帮我
答案 0 :(得分:3)
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");
}
});