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

Ton*_*bet 2 css jquery jquery-animate

我想用这个突出显示一个元素:

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

但它不起作用.

http://jsfiddle.net/Cpwmm/

为什么?

Bru*_*mes 6

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

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

然后,你应该使用:

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

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

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