2011-12-21 84 views
0

環顧四周,無法找到答案。我需要動畫的持續時間添加到該代碼:改變動畫/停止速度(持續時間)

$('a:has(.image-active)').hover(function() { 
    $('.image-active', this).stop().animate({"opacity": 1}); 
},function() { 
    $('.image-active', this).stop().animate({"opacity": 0}); 
}); 

但是,我不能工作了哪裏放置的時間。剛剛它淡入1,並淡出爲0,這必須是jQuery的默認值。

+1

http://api.jquery.com/animate/ – 2011-12-21 15:09:50

回答

2

傳遞持續時間的第二個參數動畫(),爲前:

.animate({"opacity": 1}, "fast"); 

.animate({"opacity": 1}, 3000); 
+0

感謝您的幫助,並感謝其他所有人。 – 2011-12-22 09:35:54

1

.animate()有一個參數對象:

.animate({"opacity": 1}, {duration: 100}); 

我喜歡冗長,但你也可以通過持續時間爲一個數字:

.animate({"opacity": 1}, 100); 

閱讀documentation了更多的選擇。看看例子。

0

jquery API for the .animate() method是一個偉大的地方開始。您可以在屬性之後指定動畫的持續時間(毫秒值,或「快速」或「慢」字符串)。如果我記得正確,默認值是400。

0

所有opacity首先不應該在quotes變化"opacity"opacity

.animate({opacity: 1},100); 

參考here