admin管理员组

文章数量:1327843

I want to change the background of an inputbox from white to another colour and then back to white again in a slow fading way. i have tried the animate it simply doesn't work. there is no error.

<script type="text/javascript" src="/jsp/ui/jquery-ui/js/jquery-1.8.3.min.js"></script>
...
$(document.getElementById(id)).animate({ backgroundColor: "#4E1402" }, 500);

update

This works fine

$(document.getElementById(id)).animate({ width: "400px" }, 500);

I want to change the background of an inputbox from white to another colour and then back to white again in a slow fading way. i have tried the animate it simply doesn't work. there is no error.

<script type="text/javascript" src="/jsp/ui/jquery-ui/js/jquery-1.8.3.min.js"></script>
...
$(document.getElementById(id)).animate({ backgroundColor: "#4E1402" }, 500);

update

This works fine

$(document.getElementById(id)).animate({ width: "400px" }, 500);
Share Improve this question edited May 29, 2013 at 13:35 HBP 16.1k6 gold badges29 silver badges34 bronze badges asked May 29, 2013 at 13:07 124697124697 21.9k69 gold badges197 silver badges319 bronze badges 1
  • 2 Try $('#' + id).animate({ backgroundColor: "#4E1402" }, 500); instead. – Bucket Commented May 29, 2013 at 13:09
Add a ment  | 

3 Answers 3

Reset to default 6

jQuery cannot animate color. Use this plugin instead.

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

( just a 4kb addition )

Or the jquery UI animate :

http://jqueryui./animate/ ( as mentioned by @Adam below )

You need this plugin to animate the colors with jQuery : http://archive.plugins.jquery./project/color

Have you included jquery-ui library as well?

If I remember good, current element that you are reffering to, must have some background color set at start.

本文标签: javascriptJquery background colour change animate not workingStack Overflow