最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

animation - Is there a good way to do color cycling in javascript? - Stack Overflow

programmeradmin0浏览0评论

Here's what I'd like to do: I've got a line of text in an HTML page. I'd like to have that piece of text start at a given color, cycle though the spectrum, wait a second or two, and then repeat.

I'd like to do this in javascript if possible (something like flash isn't totally out of the question, but would be some major scope creep of this project.)

I know enough JS to know this is possible, but that's about it. Can anyone point me in the right direction?

And yes, this is a real client request. I'm just glad they didn't also ask for the blink tag. ;)

Here's what I'd like to do: I've got a line of text in an HTML page. I'd like to have that piece of text start at a given color, cycle though the spectrum, wait a second or two, and then repeat.

I'd like to do this in javascript if possible (something like flash isn't totally out of the question, but would be some major scope creep of this project.)

I know enough JS to know this is possible, but that's about it. Can anyone point me in the right direction?

And yes, this is a real client request. I'm just glad they didn't also ask for the blink tag. ;)

Share Improve this question asked Jan 26, 2009 at 17:44 Electrons_AhoyElectrons_Ahoy 38.6k37 gold badges106 silver badges127 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

If you want to cycle through the spectrum, using the HSB color model is your best bet.

Related questions:

  • Color scaling function
  • Generate colors between red and green for a power meter?

I would look at some of the "fading" javascript examples on the web, and modifying them to loop with the right colors. Here's one example from the web that you could probably modify to cycle constantly.

After browsing some of the "fading" examples, we ended up going with jQuery's .animate() function and this color animation plugin. Works spectacularly.

发布评论

评论列表(0)

  1. 暂无评论