我有一個jquery動畫,在動畫完成之前從其函數運行代碼。這段代碼是在正在使用的頁面是沒有在附近完成,但是如果你想看看它的cottageboards.com/orderformjquery動畫不等待回調
$('#snow').fadeIn(500, "linear", function() {
$('#largeImage').fadeOut(500, function() {
$('#largeImage').attr('src', selectedimg).load(function() {
$('#largeImage').fadeIn(1000, function() {
//Everything below here is running before the above image's fade in is complete
$('#snow').fadeOut(5000);
var selection = 'input[name="' + $(selectionage).data('type') + '_selection"]';
$($('#selected_thumb').val()).attr('src', $($('#selected_thumb').val()).data('regular'));
$(selectionage).attr('src', $(selectionage).data('selected'));
selectedid = '#' + $(selectionage).attr('id');
$('#selected_thumb').val(selectedid);
$('#selected_info').html($(selectionage).data('desc'));
$('#name').html($(selectionage).data('name'));
if ($(selectionage).data('val') === 99) {
$('#upload').show();
$('#displayinfo').hide();
} else {
$(selection).val($(selectionage).data('val'));
$('#upload').hide();
$('#displayinfo').show();
}
$('#next').prop('disabled', false);
});
});
});
});
當重寫,以便負載的功能而來的SRC改變它像一個前魅力。謝謝你們的幫助!
工作代碼:
$('#snow').fadeIn(500, "linear", function() {
$('#largeImage').fadeOut(500, function() {
$('#largeImage').unbind().load(function() {
$('#largeImage').fadeIn(1000, function() {
$('#snow').fadeOut(5000);
var selection = 'input[name="' + $(selectionage).data('type') + '_selection"]';
$($('#selected_thumb').val()).attr('src', $($('#selected_thumb').val()).data('regular'));
$(selectionage).attr('src', $(selectionage).data('selected'));
selectedid = '#' + $(selectionage).attr('id');
$('#selected_thumb').val(selectedid);
$('#selected_info').html($(selectionage).data('desc'));
$('#name').html($(selectionage).data('name'));
if ($(selectionage).data('val') === 99) {
$('#upload').show();
$('#displayinfo').hide();
} else {
$(selection).val($(selectionage).data('val'));
$('#upload').hide();
$('#displayinfo').show();
}
$('#next').prop('disabled', false);
});
}).attr('src', selectedimg);
});
});
您應該在設置src屬性之前定義onload函數。 – r3wt
在fadein中使用done()函數查看這個文檔:http://api.jquery.com/fadein/ – aswzen
@ r3wt所以你說$('#largeimage')。load(function(){code to wait直到新來源加載在這裏})。attr('src',newsource); – TheRealMrCrowley