我要装载由AJAX一些HTML文档,但我想告诉它,当本文档中的所有图像都loded。
$('。关于)。点击(函数(){
$(回)。负载(Tour.html',函数(){
$(回)显示();
});
});
回应该是可见的,当被装载在Tour.html所有图像,当触发一个成功事件??
解决方案 $(回)。负载(Tour.html',功能(HTML){
变量$ IMGS = $(HTML).find('IMG');
变种的len = $ imgs.length,装= 0;
$ imgs.one('负荷',函数(){
加载++;
如果(装== LEN){
$(回)显示();
}
})
每个(函数(){如果(this.complete){$(本).trigger('负荷');});
});
这至少需要一个< IMG>
在返回的HTML
I want load some HTML document by AJAX, but I want to show it when all images in this document are loded.
$('.about').click(function () {
$(".back").load('Tour.html', function () {
$(".back").show();
});
});
".back" should be visible when all images in Tour.html are loaded, when is triggered a success event??
解决方案$(".back").load('Tour.html', function (html) {
var $imgs = $(html).find('img');
var len = $imgs.length, loaded = 0;
$imgs.one('load', function() {
loaded++;
if (loaded == len) {
$(".back").show();
}
})
.each(function () { if (this.complete) { $(this).trigger('load'); });
});
This requires at least one <img>
in the returned html.