3 回答

TA貢獻1841條經驗 獲得超3個贊
您可以指定一個回調函數:
$(selector).fadeOut('slow', function() {
// will be called when the element finishes fading out
// if selector matches multiple elements it will be called once for each
});

TA貢獻1712條經驗 獲得超3個贊
在jQuery 1.6版本中,您可以使用.promise()方法。
$(selector).fadeOut('slow');
$(selector).promise().done(function(){
// will be called when all the animations on the queue finish
});

TA貢獻1865條經驗 獲得超7個贊
您也可以使用$.when()等到promise完成:
var myEvent = function() {
$( selector ).fadeOut( 'fast' );
};
$.when( myEvent() ).done( function() {
console.log( 'Task finished.' );
} );
如果您執行的請求很可能失敗,那么您甚至可以更進一步:
$.when( myEvent() )
.done( function( d ) {
console.log( d, 'Task done.' );
} )
.fail( function( err ) {
console.log( err, 'Task failed.' );
} )
// Runs always
.then( function( data, textStatus, jqXHR ) {
console.log( jqXHR.status, textStatus, 'Status 200/"OK"?' );
} );
- 3 回答
- 0 關注
- 652 瀏覽
添加回答
舉報