Home

Forums

Web development

 

 

 

 
     
 
dna88 Web development and Technology Forum
 
Profile   Register   Memberlist   Usergroups   FAQ   Search  Log in
How to make the cool fading link effect like this forum?

 
Post new topic   Reply to topic    dna88 Forum Index -> Web scripting language Discussion Forum
Author Message
emm
Power User
Power User


Joined: 13 Jul 2004
Posts: 310

Post Post subject: How to make the cool fading link effect like this forum? Reply with quote

How was the nice fading effect was done for all links in this forum or quantumcloud site? Or is it my imagination? The color seems to fade gradually from red to bright gray, not just jump from one color to another. This cannot be just a hover property! Is it?
_________________
“You might say reality is the result of complex negotiations between the observer and the observed. But that is simply a point of view…”
Digital Bangladesh
Fri Sep 10, 04 3:26 am
Back to top
emm View user's profile Send private message
quantum
Site Admin
Site Admin


Joined: 07 Mar 2004
Posts: 1048
Location: Dhaka, Bangladesh

Post Post subject: Cool fading link javascript Reply with quote

The trick with the fading link color is being done with an open source Javascript. It is fairly popular too, these days I guess. You will see it used everywhere.

Here is the javascript:

Code:
fadeClasses = new Array("");
startColors = new Array("cc6600");
endColors = new Array("#33FF33");
stepIn = 15;
stepOut = 10;
autoFade = true;
sloppyClass = true;
hexa = new makearray(16);
for(var i = 0; i < 10; i++)
{
   hexa[i] = i;
}
hexa[10]="a";
hexa[11]="b";
hexa[12]="c";
hexa[13]="d";
hexa[14]="e";
hexa[15]="f";

var version = parseInt(navigator.appVersion)
var appName = navigator.appName
var n4 = version>=4 && appName=="Netscape"

document.onmouseover = (n4) ? domouseover2 : domouseover;
document.onmouseout = (n4) ? domouseout2 : domouseout;

// startColor = dehexize(startColor.toLowerCase());
// endColor = dehexize(endColor.toLowerCase());
var fadeId = new Array();

function dehexize(Color)
{
   var colorArr = new makearray(3);
   for (i=1; i<7; i++)
   {
      for (j=0; j<16; j++)
      {
         if (Color.charAt(i) == hexa[j])
         {
            if (i%2 !=0)
            {
               colorArr[Math.floor((i-1)/2)]=eval(j)*16;
            }
            else
            {
               colorArr[Math.floor((i-1)/2)]+=eval(j);
            }
         }
      }
   }
   return colorArr;
}

function domouseover()
{
   if(document.all)
   {
      var srcElement = event.srcElement;
      for(ii=0;ii<fadeClasses.length;ii++)
      {
         if((srcElement.className==fadeClasses[ii])&&(srcElement.className!=''))
         {
            startColor = dehexize(startColors[ii].toLowerCase());
            endColor = dehexize(endColors[ii].toLowerCase());
            sloppyFade = 1;
         }
         else
         {
            startColor = dehexize(startColors[0].toLowerCase());
            endColor = dehexize(endColors[0].toLowerCase());
            sloppyFade = 0;
         }
      }
      if ((srcElement.tagName == "A" && autoFade) || srcElement.className == "fade" || (sloppyClass && srcElement.className.indexOf("fade") != -1) || (sloppyClass && sloppyFade))
      {
         fade(startColor,endColor,srcElement.uniqueID,stepIn);
      }
   }
}

function domouseover2(event)
{
   var srcElement = event.target;
   for(ii=0;ii<fadeClasses.length;ii++)
   {
      if((srcElement.className==fadeClasses[ii])&&(srcElement.className!=''))
      {
         startColor = dehexize(startColors[ii].toLowerCase());
         endColor = dehexize(endColors[ii].toLowerCase());
         sloppyFade = 1;
      }
      else
      {
         startColor = dehexize(startColors[0].toLowerCase());
         endColor = dehexize(endColors[0].toLowerCase());
         sloppyFade = 0;
      }
   }
   if ((srcElement.tagName == "A" && autoFade) || srcElement.className == "fade" || (sloppyClass && srcElement.className.indexOf("fade") != -1) || (sloppyClass && sloppyFade))
   {
      fade2(startColor,endColor,srcElement,stepOut);
   }
}

function domouseout()
{
   if(document.all)
   {
      var srcElement = event.srcElement;
      for(ii=0;ii<fadeClasses.length;ii++)
      {
         if((srcElement.className==fadeClasses[ii])&&(srcElement.className!=''))
         {
            startColor = dehexize(startColors[ii].toLowerCase());
            endColor = dehexize(endColors[ii].toLowerCase());
            sloppyFade = 1;
         }
         else
         {
            startColor = dehexize(startColors[0].toLowerCase());
            endColor = dehexize(endColors[0].toLowerCase());
            sloppyFade=0;
         }
      }
      if ((srcElement.tagName == "A" && autoFade) || srcElement.className == "fade" || (sloppyClass && srcElement.className.indexOf("fade") != -1) || (sloppyClass && sloppyFade))
      {
         fade(endColor,startColor,srcElement.uniqueID,stepIn);
      }
   }
}

function domouseout2(event)
{
   var srcElement = event.target;
   for(ii=0;ii<fadeClasses.length;ii++)
   {
      if((srcElement.className==fadeClasses[ii])&&(srcElement.className!=''))
      {
         startColor = dehexize(startColors[ii].toLowerCase());
         endColor = dehexize(endColors[ii].toLowerCase());
         sloppyFade = 1;
      }
      else
      {
         startColor = dehexize(startColors[0].toLowerCase());
         endColor = dehexize(endColors[0].toLowerCase());
         sloppyFade = 0
      }
   }
   if ((srcElement.tagName == "A" && autoFade) || srcElement.className == "fade" || (sloppyClass && srcElement.className.indexOf("fade") != -1) || (sloppyClass && sloppyFade))
   {
      fade2(endColor,startColor,srcElement,stepOut);
   }
}

function makearray(n)
{
   this.length = n;
   for(var i = 1; i <= n; i++)
   {
      this[i] = 0;
   }
   return this;
}

function hex(i)
{
   if (i < 0)
   {
      return "00";
   }
  else if (i > 255)
   {
      return "ff";
   }
   else
   {
      return "" + hexa[Math.floor(i/16)] + hexa[i%16];
   }
}

function setColor(r, g, b, element)
{
   var hr = hex(r);
   var hg = hex(g);
   var hb = hex(b);
   element.style.color = "#"+hr+hg+hb;
}

function fade(s,e, element,step)
{
   var sr = s[0];
   var sg = s[1];
   var sb = s[2];
   var er = e[0];
   var eg = e[1];
   var eb = e[2];
   
   if (fadeId[0] != null && fade[0] != element)
   {
      setColor(sr,sg,sb,eval(fadeId[0]));
      var i = 1;
      while(i < fadeId.length)
      {
         clearTimeout(fadeId[i]);
         i++;
      }
   }
        // Internet Explorer timeout structure
   for(var i = 0; i <= step; i++)
   {
      fadeId[i+1] = setTimeout("setColor(Math.floor(" + sr + " *(( " + step + " - " + i + " )/ " + step + " ) + " + er + " * (" + i + "/" + step + ")),Math.floor(" + sg + " * (( " + step + " - " + i + " )/ " + step + " ) + " + eg + " * (" + i + "/" + step + ")),Math.floor(" + sb + " * ((" + step + "-" + i + ")/" + step + ") + " + eb + " * (" + i + "/" + step + "))," + element + ");", i*step);
   }
   fadeId[0] = element;
}

function fade2(s,e, element,step)
{
   var sr = s[0];
   var sg = s[1];
   var sb = s[2];
   var er = e[0];
   var eg = e[1];
   var eb = e[2];
   
   if (fadeId[0] != null && fade[0] != element)
   {
      setColor(sr,sg,sb,eval(fadeId[0]));
      var i = 1;
      while(i < fadeId.length)
      {
         clearTimeout(fadeId[i]);
         i++;
      }
   }
        // Gecko timeout structure
  for(var i = 0; i <= step; i++)
   {
      fadeId[i+1] = setTimeout(
         setColor,
         i*step,
         Math.floor(sr*((step-i)/step) + er*(i/step)),
         Math.floor(sg*((step-i)/step) + eg*(i/step)),
         Math.floor(sb*((step-i)/step) + eb*(i/step)),
         element
      );
   }
   fadeId[0] = element;
}


Save it in a .js file and then link to the file from the actual html or php page like this:

<script src="fade.js"></script> in the header section. That's all you need. You can change the beginning and end link colors near from the top. The variables are pretty self explanatory.
_________________

Dust fills my eyes / Clouds roll by / and I roll with them / Centuries cry / Orders fly / and I fall again
Afford best design, implement best solution. Outsource your web design.
Fri Sep 10, 04 5:12 am
Back to top
quantum View user's profile Send private message Visit poster's website AIM Address
emm
Power User
Power User


Joined: 13 Jul 2004
Posts: 310

Post Post subject: Reply with quote

Thanks for sharing the script. The file size is large, but I think, after the first time it will be cached so no problem with that.
_________________
“You might say reality is the result of complex negotiations between the observer and the observed. But that is simply a point of view…”
Digital Bangladesh
Sat Sep 11, 04 2:10 am
Back to top
emm View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    dna88 Forum Index -> Web scripting language Discussion Forum All times are GMT - 7 Hours
Page 1 of 1

 

Partners and Resources

Bangladesh hosting company

Bangladesh web design

Driven by phpBB © phpBB Group