2013-12-19 47 views
0

回調函數:如何在動畫完成前使用回調函數?使用

$('.caption').animate({'bottom':'0px'}, function(){$('.caption').text(data);}); 
// animates and change caption from image1 to image2 

使用回調函數動畫

$('.caption').text(data); 
$('.caption').animate({'bottom':'0px'}); 
//first change caption from image1 to image2 and animates 

之前,但我想標題從imag1改變動畫期間鏡像2。

+0

可以使用'start'屬性來執行功能,一旦動畫開始,或者你可以設置超時在特定時間在動畫開始後發生。 – Nunners

回答

0

一種辦法是打電話動畫然後設置超時改變,雖然文字一半:由於動畫設置爲1000毫秒

$('.caption').animate({'bottom':'0px'}, 1000); 
setTimeout(function(){ $('.caption').text(data); }, 500); 

,並在500毫秒超時,則文本應該改一下一半以爲他是動畫。

Here is a working example

+0

謝謝你完全按照我想要的那樣工作。 –

相關問題