Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.css().animate() not working?

I wanted to highlight an element with this:

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

But it doesn't work.

http://jsfiddle.net/Cpwmm/

why?

like image 306
Toni Michel Caubet Avatar asked May 26 '26 19:05

Toni Michel Caubet


2 Answers

To animate colors you will need to add the jQuery Animate Colors plugin.

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

Then, you should use:

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

Mind the difference that you should animate the 'background-color' property rather than the 'background' one.

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

like image 102
Bruno Gomes Avatar answered May 28 '26 12:05

Bruno Gomes


Your need the JQuery.Color plugin (part of jquery-ui). Then do,

$(document).ready(function(){
     $('input.step:last')
     .css({'backgroundColor':'#003'})
    .animate({'backgroundColor':'#fff'},300);
})​
like image 36
Diego Avatar answered May 28 '26 13:05

Diego



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!