Maybe use this demo as a guide.
Onmouseover, the link text will fade from the start colour to the end colour.
Onmouseout, the link text will fade from the current colour to the start colour.
You specify the colours using RGB. eg. 0,0,0 = black, 255,255,255 = white.
You can adjust the speed of the fading with the variables
Code:
var colourIncr = 20;
var speed = 100;
You can add as many links to the menu as you like without having to touch the javascript.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title></title>
<style type="text/css"></style>
<script type="text/javascript">
var colourIncr = 10;
var speed = 50;
function setColour(obj){
obj.redCurr += colourIncr * obj.redDir;
obj.greenCurr += colourIncr * obj.greenDir;
obj.blueCurr += colourIncr * obj.blueDir;
if(!((obj.redCurr >= obj.redStart && obj.redCurr <= obj.redEnd)
|| (obj.redCurr <= obj.redStart && obj.redCurr >= obj.redEnd))){
if(obj.redDir == 1 && obj.redStart <= obj.redEnd){obj.redCurr = obj.redEnd};
if(obj.redDir == 1 && obj.redStart >= obj.redEnd){obj.redCurr = obj.redStart};
if(obj.redDir == -1 && obj.redStart <= obj.redEnd){obj.redCurr = obj.redStart};
if(obj.redDir == -1 && obj.redStart >= obj.redEnd){obj.redCurr = obj.redEnd};
}
if(!((obj.greenCurr >= obj.greenStart && obj.greenCurr <= obj.greenEnd)
|| (obj.greenCurr <= obj.greenStart && obj.greenCurr >= obj.greenEnd))){
if(obj.greenDir == 1 && obj.greenStart <= obj.greenEnd){obj.greenCurr = obj.greenEnd};
if(obj.greenDir == 1 && obj.greenStart >= obj.greenEnd){obj.greenCurr = obj.greenStart};
if(obj.greenDir == -1 && obj.greenStart <= obj.greenEnd){obj.greenCurr = obj.greenStart};
if(obj.greenDir == -1 && obj.greenStart >= obj.greenEnd){obj.greenCurr = obj.greenEnd};
}
if(!((obj.blueCurr >= obj.blueStart && obj.blueCurr <= obj.blueEnd)
|| (obj.blueCurr <= obj.blueStart && obj.blueCurr >= obj.blueEnd))){
if(obj.blueDir == 1 && obj.blueStart <= obj.blueEnd){obj.blueCurr = obj.blueEnd};
if(obj.blueDir == 1 && obj.blueStart >= obj.blueEnd){obj.blueCurr = obj.blueStart};
if(obj.blueDir == -1 && obj.blueStart <= obj.blueEnd){obj.blueCurr = obj.blueStart};
if(obj.blueDir == -1 && obj.blueStart >= obj.blueEnd){obj.blueCurr = obj.blueEnd};
}
obj.style.color = 'rgb('+obj.redCurr+', '+ obj.greenCurr + ', '+ obj.blueCurr +')';
obj.timer = setTimeout(function(){setColour(obj)},speed);
}
window.onload=function(){
oLinks = document.getElementById('topnav').getElementsByTagName('a');
for(i=0; i < oLinks.length; i++){
//set the start colour
oLinks[i].redStart = 0;
oLinks[i].greenStart = 0;
oLinks[i].blueStart = 0;
//set the end colour
oLinks[i].redEnd = 255;
oLinks[i].greenEnd = 255;
oLinks[i].blueEnd = 255;
oLinks[i].redCurr = oLinks[i].redStart;
oLinks[i].greenCurr = oLinks[i].greenStart;
oLinks[i].blueCurr = oLinks[i].blueStart;
oLinks[i].style.color = 'rgb('+oLinks[i].redCurr+', '+ oLinks[i].greenCurr +', '+ oLinks[i].blueCurr +')';
oLinks[i].onmouseover=function(){
if(this.timer){clearTimeout(this.timer)};
this.redDir = (this.redStart <= this.redEnd)? 1 : -1;
this.greenDir = (this.greenStart <= this.greenEnd)? 1 : -1;
this.blueDir = (this.blueStart <= this.blueEnd)? 1 : -1;
setColour(this);
}
oLinks[i].onmouseout=function(){
if(this.timer){clearTimeout(this.timer)};
this.redDir = (this.redStart <= this.redEnd)? -1 : 1;
this.greenDir = (this.greenStart <= this.greenEnd)? -1 : 1;
this.blueDir = (this.blueStart <= this.blueEnd)? -1 : 1;
setColour(this);
}
}
}
</script>
</head>
<body>
<ol id="topnav">
<li><a href="#">portfolio</a></li>
<li><a href="#">about</a></li>
<li><a href="#">contact</a></li>
</ol>
</body>
</html>
If I spend more time on this demo I might be able to optimise it a bit more but it works as is and hopefully you'll get at least the jist of how it works