Go Back   CodingForums.com > :: Client side development > JavaScript programming > Post a JavaScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-10-2003, 04:13 AM   PM User | #1
bluephoenix
New Coder

 
Join Date: Dec 2002
Location: Central New York
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
bluephoenix is an unknown quantity at this point
Smile JavaScript Strobing Rainbow Links

Good Evening.

I had this idea to implement on the Kid's Activities page on the website for work and after hours and hours and hours of laboriously slaving over code (yeah, right... more like an hour, most of which was spent formatting and commenting the code) I just had to share it with people.

Really, it's not that long but it's pretty well documented throughout and adhears to the PHP/PEAR formatting rules so it looks rather spread out. The code itself probably isn't as streamlined as it could be, either... the "?:" operator instead of an IF-THEN statement and the FOR statement instead of WHILE-LOOP help, but there's always extra tweeks that could be made. I wanted to get the idea out there, though.

I've also posted the code on the cyberdevdigest website at cyberdevdigest.com/code/javascript/rainbow_links.html.

-Tim

Code:
 
   <script type='text/javascript'>
   <!--
   // JavaScript code to produce strobing rainbow-colored links
   // on mouseovers. Coded by Timothy Boronczyk, © 2003.

   // declare list of colors as a global array (goldenrod used 
   // because yellow was too difficult to against lighter 
   // backgrounds)
   var colors = Array('red', 'orange', 'goldenrod', 'green',
                      'blue', 'purple');

   // declare color pointer (current color in array by position)
   var p_color = 0;

   function strobe(x)
   {
       // set pointer to next color (reset pointer to beginning
       // if current position is at the end of the list)
       p_color = (p_color == 5) ? 0 : p_color + 1;

       // set link color
       document.links[x].style.color = colors[p_color];

       return true; // no errors
   }

   function rainbow(link, toggle)
   {
       // determine which link called this function by matching
       // the current key of the DOM's link array
       for (id = 0; link != document.links[id]; id++);

       if (toggle)
       {
           // identify setInterval function by name cycle and 
           // repeatedly call change_color passing current link
           // array key
           cycle = setInterval('strobe(id)', 100);
       }
       else
       {
           // terminate cycle calls
           clearInterval(cycle);

           // reset link color (assuming that green was original
           // color)
           link.style.color = 'green';
       }

       return true; // no errors
   }
   //-->
   </script>
call using onmouseover and onmouseout event handlers, such as in this example:
Code:
  
   <a href='link.html' onmouseover="rainbow(this, 1);"
      onmouseout="rainbow(this, 0);">CLICK HERE</a>
__________________
Timothy Boronczyk
bluephoenix is offline   Reply With Quote
Old 07-20-2003, 06:08 AM   PM User | #2
Scrowler
Regular Coder

 
Join Date: Jul 2003
Location: New Zealand
Posts: 435
Thanks: 1
Thanked 0 Times in 0 Posts
Scrowler is an unknown quantity at this point
Thumbs up

nice work
Scrowler is offline   Reply With Quote
Old 07-21-2003, 10:19 AM   PM User | #3
fredmv
Regular Coder

 
Join Date: Jul 2003
Location: Massachusetts
Posts: 472
Thanks: 0
Thanked 0 Times in 0 Posts
fredmv is an unknown quantity at this point
Nice job Tim.
__________________
Moderator @ WebDeveloper.com
Mentor @ WebXpertz.net
fredmv is offline   Reply With Quote
Old 08-08-2003, 02:31 AM   PM User | #4
bluephoenix
New Coder

 
Join Date: Dec 2002
Location: Central New York
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
bluephoenix is an unknown quantity at this point
Thanks

-Tim
__________________
Timothy Boronczyk
bluephoenix is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:12 PM.


Advertisement
Log in to turn off these ads.