1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| <html>
<title>Span Color Cycle Demo</title>
<head>
<!--- *** BEGIN CUT - Demo starts here *** --->
<!-- * You may use this code for free on any web page provided that
* these comment lines and the following credits remain in the code.
* "Link Color Cycle" � http://www.javascript-fx.com
-->
<script type="text/javascript">
/***********************************************
*
* Function : getColor
*
* Parameters : start - the start color (in the form "RRGGBB" e.g. "FF00AC")
* end - the end color (in the form "RRGGBB" e.g. "FF00AC")
* percent - the percent (0-100) of the fade between start & end
*
* returns : color in the form "#RRGGBB" e.g. "#FA13CE"
*
* Description : This is a utility function. Given a start and end color and
* a percentage fade it returns a color in between the 2 colors
*
* Author : www.JavaScript-FX.com
*
*************************************************/
function getColor(start, end, percent){
function hex2dec(hex){return(parseInt(hex,16));}
function dec2hex(dec){return (dec < 16 ? "0" : "") + dec.toString(16);}
var r1 = hex2dec(start.slice(0,2)), g1=hex2dec(start.slice(2,4)), b1=hex2dec(start.slice(4,6));
var r2 = hex2dec(end.slice(0,2)), g2=hex2dec(end.slice(2,4)), b2=hex2dec(end.slice(4,6));
var pc = percent/100;
var r = Math.floor(r1+(pc*(r2-r1)) + .5), g=Math.floor(g1+(pc*(g2-g1)) + .5), b=Math.floor(b1+(pc*(b2-b1)) + .5);
return("#" + dec2hex(r) + dec2hex(g) + dec2hex(b));
}
/************************************************/
</script>
<script>
var colors = new Array("339966", "FF0000", "00FF00", "0000FF", "FFFF00", "FF00FF", "00FFFF", "FFffff", "000000", "ffffff", "cccccc", "999999", "333333");
var start = colors[0];
var end = colors[0];
var index = 0;
var cindex = 0;
var faderObj = new Array();
function fadeSpan()
{
if(index == 0)
{
start = end;
end = colors[ cindex = (cindex+1) % colors.length ];
}
// document.getElementById("fadingText").style.color = getColor(start, end, index);
for(var i=0 ; i<faderObj.length ; i++)
faderObj[i].style.color = getColor(start, end, index);
index = (index+5) % 100;
setTimeout("fadeSpan()", 100);
}
function fadeAll()
{
for(var i=0 ; i<arguments.length ; i++)
faderObj[i] = document.getElementById(arguments[i]);
fadeSpan();
}
function JSFX_StartEffects()
{
fadeAll("sp1","sp2");
}
</script>
<!--- *** END CUT - Demo ends here *** --->
</head>
<body bgcolor="#000000" text="white" onLoad="JSFX_StartEffects()">
Here is a test of the spanfader <span id="sp1">HERE IS SOME TEXT CHANGING COLORS</a></span>. You can
<span id="sp2">Make any span</a></span> a color cycling one.
</body>
</html> |