7

我想在完全加载背景图像后触发一个事件。该图像由动态 PHP 脚本制成。

$("#box").css("background-image","url(image.php)");

也许我可以尝试让图像处于不可见<img>状态,并且当图像加载(.load())使用该不可见的 src 设置背景图像<img>?没有把握...

感谢您的帮助。

4

2 回答 2

10

你可以使用我的名为waitForImages的 jQuery 插件来帮助解决这个问题......

$("#box").css("background-image", "url(image.php)").waitForImages({
   waitForAll: true,
   finished: function() {
       // Background image has loaded.
   }
});

否则,手动执行...

var image = 'image.php',

    img = $('<img />');

img.bind('load', function() {
     // Background image has loaded.
});

img.attr('src', image);

$('#box').css('background-image', 'url(' + image + ')');
于 2011-10-28T06:51:32.107 回答
-1
$("#box img").load(function() {  
    //the image elements in #box are fully loaded.
});
于 2011-10-28T06:49:50.283 回答