$(function(){
// html文档加载完成后触发(不包含外部文件图片等)
})
$("img").load(function(){
// 单张图片加载完成后触发
})
下面的代码判断所有图片加载完成:
$(function(){
var imgdefereds=[];
$('img').each(function(){
var dfd=$.Deferred();
$(this).bind('load',function(){
dfd.resolve();
}).bind('error',function(){
//图片加载错误,加入错误处理
// dfd.resolve();
})
if(this.complete) setTimeout(function(){
dfd.resolve();
},1000);
imgdefereds.push(dfd);
})
$.when.apply(null,imgdefereds).done(function(){
callback(); // 全部图片加载完成触发的回调函数
});
// html文档加载完成后触发(不包含外部文件图片等)
})
$("img").load(function(){
// 单张图片加载完成后触发
})
下面的代码判断所有图片加载完成:
$(function(){
var imgdefereds=[];
$('img').each(function(){
var dfd=$.Deferred();
$(this).bind('load',function(){
dfd.resolve();
}).bind('error',function(){
//图片加载错误,加入错误处理
// dfd.resolve();
})
if(this.complete) setTimeout(function(){
dfd.resolve();
},1000);
imgdefereds.push(dfd);
})
$.when.apply(null,imgdefereds).done(function(){
callback(); // 全部图片加载完成触发的回调函数
});
})