目前,当您打开对话框时,您的加载会停止,因此,如果您延迟打开对话框,加载将不会发生任何事情。因此,如果您想在打开对话框之前加载图像,那么您不应该在 open 函数中加载 div 主体。
我还没有测试过它,但类似的东西可能会起作用:1. 将 body 加载到隐藏的 div 2. 检查器功能的启动间隔,以查看所有图像何时加载。3.打开对话框
var eld = $('<div style="display:none" class="loading"></div>').appendTo('body');
eld.dialog({
autoOpen: false,
open: function() {
},
close: function(event, ui) {
eld.remove();
},
modal: true,
height: 385,
width: 750
});
function IsImageOk(img) {
// During the onload event, IE correctly identifies any images that
// weren’t downloaded as not complete. Others should too. Gecko-based
// browsers act like NS4 in that they report this incorrectly.
if (!img.complete) {
return false;
}
// However, they do have two very useful properties: naturalWidth and
// naturalHeight. These give the true size of the image. If it failed
// to load, either of these should be zero.
if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
return false;
}
// No other way of checking: assume it’s ok.
return true;
}
//Function for checking all images
function chk_images(where)
{
var img_count = $('img', where);
var ok_count = 0;
$('img', where).each(function(){
if (IsImageOk($(this).get(0)) )
{
ok_count++;
}
});
if (ok_count == img_count) return true;
return false;
}
eld.html('').load ("img_swiper.php?img_url="+url, function() {
//Set up checker function
var interval = setInterval(function(){
//Check images inside eld
if (chk_images(eld))
{
//Stop futher checking
clearInterval(interval);
eld.dialog('open');
}
},1000);
$('.ui-widget-overlay').bind('click', function() {
eld.dialog('close');
});
});
如果浏览器不想在隐藏的 div 中加载图像,那么您可以将此 div 以绝对位置移出屏幕并使其可见以加载 porpouse。像 eld.css({position:'absolute',top: '-1000px',left: '-1000px'});
检查 Allso: