2011-12-21 85 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