.css()。animate()不工作?

时间:2012-03-02 15:43:03

标签: jquery css jquery-animate

我想突出显示一个元素:

$('input.step:last').css('background','#003').animate({'background':'#fff'},300);

但它不起作用。

http://jsfiddle.net/Cpwmm/

为什么?

3 个答案:

答案 0 :(得分:6)

要为颜色设置动画,您需要添加jQuery Animate Colors插件。

http://www.bitstorm.org/jquery/color-animation/

然后,你应该使用:

$('input.step:last').css('background-color','#003')
                    .animate({'background-color':'#fff'},300);

注意你应该为'background-color'属性设置动画而不是'background'属性。

http://jsfiddle.net/Cpwmm/7/

答案 1 :(得分:2)

您需要JQuery.Color插件(jquery-ui的一部分)。然后呢,

$(document).ready(function(){
     $('input.step:last')
     .css({'backgroundColor':'#003'})
    .animate({'backgroundColor':'#fff'},300);
})​

答案 2 :(得分:1)

默认情况下,jQuery can’t animate colors。您可以使用jQuery.color() plugin, found here,为其提供该功能。