Time Until Wedding
Days
Hours
Minutes
Seconds
 
Navigation
 
Search
 
My Usable Projects
 
Reading...
 
Listening...
 
Random Image
Hobbs_0061.jpg
 
Archives
 
Me. Elsewhere.
 
Feeds and Such

Google Reader or Homepage
Add to My Yahoo!
Add to Technorati Favorites!
Bookmark del.icio.us
Bookmark Furl
Bookmark Spurl
 
Darcy
 
Things I Like
Sidux Linux
 
License
 
Javascript Colorshifter

I wrote this little function because I wanted a little background color shifter without having to deal with a big script animation library. Really simple, and it takes some time to run through itself. I’ll rewrite it to be faster, more flexible later.

Actually I probably won’t.

Anyway, here it is, and heres a demo. Multiple clicks will get you psycho function timeouts all over the place and some strange color changes. Rad.

1
2
3
4
5
6
7
8
function colorShift(strTarget,sR,sG,sB,tR,tG,tB) {
  if(sR == tR && sG == tG && sB == tB) { return; }
  if(sR != tR) { (sR < tR) ? sR++ : sR--; }
  if(sG != tG) { (sG < tG) ? sG++ : sG--; }
  if(sB != tB) { (sB < tB) ? sB++ : sB--; }
  document.getElementById(strTarget).style.backgroundColor = "rgb("+sR+","+sG+","+sB+")";
  setTimeout("colorShift('"+strTarget+"',"+sR+","+sG+","+sB+","+tR+","+tG+","+tB+")",1);
}

Now that I look, it’s sorta related to the Javascript Attention Grabber from earlier this month.

Posted November 22nd, 2006 - Permalink
Categories: JavaScript - Programming - Snippets
You can leave a comment, or trackback from your own site.
 
Adjacent Posts
 
Comments