3

I want an equivalent of fadeTo() for colors, instead of opacity.

For example, starting with backgroundColor = "red", how can I gradually move to backgroundColor = "green" with jQuery?

Randomblue
  • 112,777
  • 145
  • 353
  • 547

2 Answers2

4

You need to use jQuery UI Color Animation.

You may also use CSS3 transitions which I prefer. Not supported in Internet Explorer 9 or older. Will be supported in Internet Explorer 10.

knut
  • 4,699
  • 4
  • 33
  • 43
4

You could use animate()

 $('#yourdiv').animate({ backgroundColor: "green" }, 1000)
Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192
  • Actually, this doesn't seem to work. Here is was the documentation says: "All animated properties should be animated to a single numeric value, except as noted below; most properties that are non-numeric cannot be animated using basic jQuery functionality. (For example, `width`, `height`, or `left` can be animated but `background-color` cannot be.)" – Randomblue Jul 24 '11 at 21:02