pel*_*ive 7 jquery background image loaded
我想在后台图像被完全加载后触发事件.该图像由动态PHP脚本构成.
$("#box").css("background-image","url(image.php)");
Run Code Online (Sandbox Code Playgroud)
也许我可以尝试将图像置于不可见状态<img>,当图像加载(.load())将背景图像设置为不可见的src时<img>?不确定...
谢谢您的帮助.
ale*_*lex 10
您可以使用我的jQuery插件waitForImages来帮助解决这个问题...
$("#box").css("background-image", "url(image.php)").waitForImages({
waitForAll: true,
finished: function() {
// Background image has loaded.
}
});
Run Code Online (Sandbox Code Playgroud)
否则,手动完成...
var image = 'image.php',
img = $('<img />');
img.bind('load', function() {
// Background image has loaded.
});
img.attr('src', image);
$('#box').css('background-image', 'url(' + image + ')');
Run Code Online (Sandbox Code Playgroud)