3
我想要做的是做一些行動發生時,通過Ajax兩個同時圖像加載完成。爲此,我創建了一個自定義延遲,以在圖像加載完成時解析。
<div id="i"></div>
$(document).ready(function() {
$('#i').hide();
var imgLoad = loadImgs();
$.when(imgLoad).then(function() {
$('#i').show('slow');
});
});
function loadImgs() {
var dfd = $.Deferred();
var matrix = $.getJSON("https://graph.facebook.com/thematrixmovie");
var pulp = $.getJSON("https://graph.facebook.com/pulpfiction");
$.when(matrix, pulp).then(function(m, p) {
mImg = '<img src=' + m[0].picture + '>';
pImg = '<img src=' + p[0].picture + '>';
$('#i').show().append(mImg + pImg);
dfd.resolve;
});
return dfd.promise();
}
你可以試試這個on JSFiddle。
我已經使用了Eric Hynds post,包括一個working example作爲參考,但仍然沒有得到它的工作。有任何想法嗎?