Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery AJAX:获取html并检查图像是否已完成加载_Jquery_Ajax - Fatal编程技术网

Jquery AJAX:获取html并检查图像是否已完成加载

Jquery AJAX:获取html并检查图像是否已完成加载,jquery,ajax,Jquery,Ajax,我正在使用AJAX将html和图像加载到特定的容器中。 我需要设置封闭容器高度的动画,因此我尝试: // load content var id = $(this).data('id'); $.get('content/'+id+'/html/content.html', function(data) { // insert html $('#overlay-inner').html(data); // show overlay $('#overlay').f

我正在使用AJAX将html和图像加载到特定的容器中。 我需要设置封闭容器高度的动画,因此我尝试:

// load content
var id = $(this).data('id');
$.get('content/'+id+'/html/content.html', function(data) {

    // insert html
    $('#overlay-inner').html(data);

    // show overlay
    $('#overlay').fadeIn();

    // add new height to wrapper
    var height = $('#overlay').height() + 200;
    console.log(height);
    $('#wrapper').animate({'height':height});

});
不幸的是,它只在某些时候起作用,因为高度不正确。加载的数据包含一些图像,它们需要一点时间来加载


是否有任何方法可以检查是否加载了所有图像,以便在完成加载后设置高度动画?

使用ImagesLoaded插件:

请参阅该页以获取示例


jQuery
$().load
无法工作,因为它在图像已缓存时不会启动(请参见)

slevin您是否在文档中调用它。Ready答案与您所说的正好相反。@Asad Right。相应地修改了我的答案。太好了!这正是我需要的!:)@Samuel我认为这只适用于直接连接到图像的加载处理程序,而不适用于窗口。