onMouseover cell color change...?
- joebert
- Sledgehammer


- Joined: Feb 10, 2004
- Posts: 13455
- Loc: Florida
- Status: Offline
I had the same problem with trying to get links and cells to fade at the same time by using the two scripts, that I now think is caused by set and clear intervals canceling eachother out. I'm about to combine the two scripts into one and see what happens 
Strong with this one, the sudo is.
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
March 30th, 2004, 12:23 pm
- oblongintellect
- Novice


- Joined: Mar 23, 2004
- Posts: 28
- Status: Offline
- stickfigure
- Beginner


- Joined: Mar 28, 2004
- Posts: 49
- Status: Offline
- joebert
- Sledgehammer


- Joined: Feb 10, 2004
- Posts: 13455
- Loc: Florida
- Status: Offline
Edit: Found time to play with it a little more
[new] moved all params to the top in hex for easier input
[new] fixed the color glitches
[new] added border options (no fade yet)
[new] XHTML'ed the example (just for the shmell of it)
[new] fade is smoother
[NOTE] you still have to define the original colors in your cells and texts (or css), I set it up the way it is for an easier edit when I figure out how to capture all the documents color values. For now the "orig" variables serve as reference for the fading, make sure they match your css/colors.
working example: IE6, NS7, FFox08 tested
[new] moved all params to the top in hex for easier input
[new] fixed the color glitches
[new] added border options (no fade yet)
[new] XHTML'ed the example (just for the shmell of it)
[new] fade is smoother
[NOTE] you still have to define the original colors in your cells and texts (or css), I set it up the way it is for an easier edit when I figure out how to capture all the documents color values. For now the "orig" variables serve as reference for the fading, make sure they match your css/colors.
working example: IE6, NS7, FFox08 tested
Code: [ Select ]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content=
"text/html; charset=us-ascii" />
<title>cross-fade</title>
<script language="javascript" type="text/javascript">
//<![CDATA[
var speed = 40; // milliseconds between each step of transition
var steps = 20; // amount to + or - by each step of transition
var fadeToText = "7788ff"; // color for text to fade to
var fadeToCell = "f0f0f0"; // color for cell to fade to
var origText = "ffffff"; // original text color
var origCell = "7788ff"; // original cell color
var newBorder = "56789a"; // border hover color
var origBorder = "99aaff"; // original border color
dC21 = new Array(hextodec(origText.substring(0, 2)),hextodec(origText.substring(2, 4)),hextodec(origText.substring(4, 6)));
dC22 = new Array(hextodec(fadeToText.substring(0, 2)),hextodec(fadeToText.substring(2, 4)),hextodec(fadeToText.substring(4, 6)));
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 hexnumtodec(hexchar) {
if (parseInt(hexchar) == hexchar) return Number(hexchar)
hexchar = hexchar.toUpperCase()
switch (hexchar) {
case 'A': return 10; break;
case 'B': return 11; break;
case 'C': return 12; break;
case 'D': return 13; break;
case 'E': return 14; break;
case 'F': return 15; break;
}
}
function hextodec(daHex) {
var daDec = Number((16 * hexnumtodec(daHex.substring(0,1))) + hexnumtodec(daHex.substring(1,2)))
return daDec
}
function convert2Dec(hex)
{
var rgb = new Array();
for (var u = 0; u < 3; u++)
rgb[u] = parseInt(hex.substring(u*2, u*2+2), 16);
return rgb;
}
mode = true;
function setColor(r,g,b,what) {
var hr = hex(r); var hg = hex(g); var hb = hex(b);
var daColor = "#"+hr+hg+hb
if(mode){
daEl.style.backgroundColor = daColor;
mode = false;
}
else{
if(dC21[0] < dC22[0]) dC21[0] += step;
if(dC21[0] > dC22[0]) dC21[0] -= step;
if(dC21[1] < dC22[1]) dC21[1] += step;
if(dC21[1] > dC22[1]) dC21[1] -= step;
if(dC21[2] < dC22[2]) dC21[2] += step;
if(dC21[2] > dC22[2]) dC21[2] -= step;
dC2B = "RGB(" + dC21[0] + "," + dC21[1] + "," + dC21[2] + ")";
daEl.style.color = dC2B;
mode = true;
}
if (daColor == colorend.toLowerCase()) {
dC21[0] = hextodec(origText.substring(0, 2));
dC21[1] = hextodec(origText.substring(2, 4));
dC21[2] = hextodec(origText.substring(4, 6));
dC2B = "RGB(" + dC22[0] + "," + dC22[1] + "," + dC22[2] + ")";
daEl.style.color = dC2B;
clearInterval(iId)
iId = null
timerRunning = false
mode = true
}
}
function fade(what) {
i++
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)),
what);
}
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 i
var iId = null
var sr, sg, sb
var er, eg, eb
var interval = 1
var step = 16
var colorstart
var colorend
var daEl
var timerRunning = false
function myfade(el,cs,ce,iv,st) {
daEl = el
colorstart = cs
colorend = ce
interval = iv
step = st
i = 0
if (timerRunning) {
clearInterval(iId)
iId = null
}
var myRe = /#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i
if (colorstart.match(myRe)) {
sr = hextodec(RegExp.$1)
sg = hextodec(RegExp.$2)
sb = hextodec(RegExp.$3)
}
if (colorend.match(myRe)) {
er = hextodec(RegExp.$1)
eg = hextodec(RegExp.$2)
eb = hextodec(RegExp.$3)
}
timerRunning = false;
iId = setInterval("fade()",interval)
timerRunning = true;
}
function orig(tc){
dC21[0] = hextodec(origText.substring(0, 2));
dC21[1] = hextodec(origText.substring(2, 4));
dC21[2] = hextodec(origText.substring(4, 6));
tc.style.backgroundColor = "#" + origCell;
tc.style.borderColor = "#" + origBorder;
tc.style.color = "#" + origText;
}
function cellover1(tc) {
orig(tc);
colorNow = "#" + origCell;
colorTo = "#" + fadeToCell;
myfade(tc,colorNow,colorTo,speed,steps)
tc.style.borderColor = "#" + newBorder;
}
function cellout1(tc) {
clearInterval(iId)
tc.style.borderColor = "#" + origBorder;
orig(tc);
}
//]]>
</script>
<style type="text/css">
/*<![CDATA[*/
.navA{position:absolute; left:20px; top:10px; width:120px;}
td,.navA{border:#99aaff 1px solid; font-size:12px; font-family:Verdana,Tahoma;}
tr{height:20px;}
/*]]>*/
</style>
</head>
<body>
<div class="navA">
<table cellspacing="0" width="100%" style=
"cursor:pointer; background:#7788ff; color:#ffffff;">
<tr>
<td onmouseover="cellover1(this)" onmouseout=
"cellout1(this)" onclick="window.location.href='http://www.ozzu.com'">OZZU</td>
</tr>
<tr>
<td onmouseover="cellover1(this)" onmouseout=
"cellout1(this)" onclick="window.open('http://www.google.com')">Google</td>
</tr>
<tr>
<td onmouseover="cellover1(this)" onmouseout=
"cellout1(this)" onclick="window.location.href='http://www.bigwebmaster.com'">BWM.com</td>
</tr>
<tr>
<td onmouseover="cellover1(this)" onmouseout=
"cellout1(this)" onclick="window.location.href='http://www.unflux.com'">UNFLUX.com</td>
</tr>
<tr>
<td onmouseover="cellover1(this)" onmouseout=
"cellout1(this)" onclick="window.location.href='http://www.reptilerooms.com'">Reptile Rooms</td>
</tr>
</table>
</div>
</body>
</html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content=
"text/html; charset=us-ascii" />
<title>cross-fade</title>
<script language="javascript" type="text/javascript">
//<![CDATA[
var speed = 40; // milliseconds between each step of transition
var steps = 20; // amount to + or - by each step of transition
var fadeToText = "7788ff"; // color for text to fade to
var fadeToCell = "f0f0f0"; // color for cell to fade to
var origText = "ffffff"; // original text color
var origCell = "7788ff"; // original cell color
var newBorder = "56789a"; // border hover color
var origBorder = "99aaff"; // original border color
dC21 = new Array(hextodec(origText.substring(0, 2)),hextodec(origText.substring(2, 4)),hextodec(origText.substring(4, 6)));
dC22 = new Array(hextodec(fadeToText.substring(0, 2)),hextodec(fadeToText.substring(2, 4)),hextodec(fadeToText.substring(4, 6)));
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 hexnumtodec(hexchar) {
if (parseInt(hexchar) == hexchar) return Number(hexchar)
hexchar = hexchar.toUpperCase()
switch (hexchar) {
case 'A': return 10; break;
case 'B': return 11; break;
case 'C': return 12; break;
case 'D': return 13; break;
case 'E': return 14; break;
case 'F': return 15; break;
}
}
function hextodec(daHex) {
var daDec = Number((16 * hexnumtodec(daHex.substring(0,1))) + hexnumtodec(daHex.substring(1,2)))
return daDec
}
function convert2Dec(hex)
{
var rgb = new Array();
for (var u = 0; u < 3; u++)
rgb[u] = parseInt(hex.substring(u*2, u*2+2), 16);
return rgb;
}
mode = true;
function setColor(r,g,b,what) {
var hr = hex(r); var hg = hex(g); var hb = hex(b);
var daColor = "#"+hr+hg+hb
if(mode){
daEl.style.backgroundColor = daColor;
mode = false;
}
else{
if(dC21[0] < dC22[0]) dC21[0] += step;
if(dC21[0] > dC22[0]) dC21[0] -= step;
if(dC21[1] < dC22[1]) dC21[1] += step;
if(dC21[1] > dC22[1]) dC21[1] -= step;
if(dC21[2] < dC22[2]) dC21[2] += step;
if(dC21[2] > dC22[2]) dC21[2] -= step;
dC2B = "RGB(" + dC21[0] + "," + dC21[1] + "," + dC21[2] + ")";
daEl.style.color = dC2B;
mode = true;
}
if (daColor == colorend.toLowerCase()) {
dC21[0] = hextodec(origText.substring(0, 2));
dC21[1] = hextodec(origText.substring(2, 4));
dC21[2] = hextodec(origText.substring(4, 6));
dC2B = "RGB(" + dC22[0] + "," + dC22[1] + "," + dC22[2] + ")";
daEl.style.color = dC2B;
clearInterval(iId)
iId = null
timerRunning = false
mode = true
}
}
function fade(what) {
i++
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)),
what);
}
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 i
var iId = null
var sr, sg, sb
var er, eg, eb
var interval = 1
var step = 16
var colorstart
var colorend
var daEl
var timerRunning = false
function myfade(el,cs,ce,iv,st) {
daEl = el
colorstart = cs
colorend = ce
interval = iv
step = st
i = 0
if (timerRunning) {
clearInterval(iId)
iId = null
}
var myRe = /#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i
if (colorstart.match(myRe)) {
sr = hextodec(RegExp.$1)
sg = hextodec(RegExp.$2)
sb = hextodec(RegExp.$3)
}
if (colorend.match(myRe)) {
er = hextodec(RegExp.$1)
eg = hextodec(RegExp.$2)
eb = hextodec(RegExp.$3)
}
timerRunning = false;
iId = setInterval("fade()",interval)
timerRunning = true;
}
function orig(tc){
dC21[0] = hextodec(origText.substring(0, 2));
dC21[1] = hextodec(origText.substring(2, 4));
dC21[2] = hextodec(origText.substring(4, 6));
tc.style.backgroundColor = "#" + origCell;
tc.style.borderColor = "#" + origBorder;
tc.style.color = "#" + origText;
}
function cellover1(tc) {
orig(tc);
colorNow = "#" + origCell;
colorTo = "#" + fadeToCell;
myfade(tc,colorNow,colorTo,speed,steps)
tc.style.borderColor = "#" + newBorder;
}
function cellout1(tc) {
clearInterval(iId)
tc.style.borderColor = "#" + origBorder;
orig(tc);
}
//]]>
</script>
<style type="text/css">
/*<![CDATA[*/
.navA{position:absolute; left:20px; top:10px; width:120px;}
td,.navA{border:#99aaff 1px solid; font-size:12px; font-family:Verdana,Tahoma;}
tr{height:20px;}
/*]]>*/
</style>
</head>
<body>
<div class="navA">
<table cellspacing="0" width="100%" style=
"cursor:pointer; background:#7788ff; color:#ffffff;">
<tr>
<td onmouseover="cellover1(this)" onmouseout=
"cellout1(this)" onclick="window.location.href='http://www.ozzu.com'">OZZU</td>
</tr>
<tr>
<td onmouseover="cellover1(this)" onmouseout=
"cellout1(this)" onclick="window.open('http://www.google.com')">Google</td>
</tr>
<tr>
<td onmouseover="cellover1(this)" onmouseout=
"cellout1(this)" onclick="window.location.href='http://www.bigwebmaster.com'">BWM.com</td>
</tr>
<tr>
<td onmouseover="cellover1(this)" onmouseout=
"cellout1(this)" onclick="window.location.href='http://www.unflux.com'">UNFLUX.com</td>
</tr>
<tr>
<td onmouseover="cellover1(this)" onmouseout=
"cellout1(this)" onclick="window.location.href='http://www.reptilerooms.com'">Reptile Rooms</td>
</tr>
</table>
</div>
</body>
</html>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content=
- "text/html; charset=us-ascii" />
- <title>cross-fade</title>
- <script language="javascript" type="text/javascript">
- //<![CDATA[
- var speed = 40; // milliseconds between each step of transition
- var steps = 20; // amount to + or - by each step of transition
- var fadeToText = "7788ff"; // color for text to fade to
- var fadeToCell = "f0f0f0"; // color for cell to fade to
- var origText = "ffffff"; // original text color
- var origCell = "7788ff"; // original cell color
- var newBorder = "56789a"; // border hover color
- var origBorder = "99aaff"; // original border color
- dC21 = new Array(hextodec(origText.substring(0, 2)),hextodec(origText.substring(2, 4)),hextodec(origText.substring(4, 6)));
- dC22 = new Array(hextodec(fadeToText.substring(0, 2)),hextodec(fadeToText.substring(2, 4)),hextodec(fadeToText.substring(4, 6)));
- 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 hexnumtodec(hexchar) {
- if (parseInt(hexchar) == hexchar) return Number(hexchar)
- hexchar = hexchar.toUpperCase()
- switch (hexchar) {
- case 'A': return 10; break;
- case 'B': return 11; break;
- case 'C': return 12; break;
- case 'D': return 13; break;
- case 'E': return 14; break;
- case 'F': return 15; break;
- }
- }
- function hextodec(daHex) {
- var daDec = Number((16 * hexnumtodec(daHex.substring(0,1))) + hexnumtodec(daHex.substring(1,2)))
- return daDec
- }
- function convert2Dec(hex)
- {
- var rgb = new Array();
- for (var u = 0; u < 3; u++)
- rgb[u] = parseInt(hex.substring(u*2, u*2+2), 16);
- return rgb;
- }
- mode = true;
- function setColor(r,g,b,what) {
- var hr = hex(r); var hg = hex(g); var hb = hex(b);
- var daColor = "#"+hr+hg+hb
- if(mode){
- daEl.style.backgroundColor = daColor;
- mode = false;
- }
- else{
- if(dC21[0] < dC22[0]) dC21[0] += step;
- if(dC21[0] > dC22[0]) dC21[0] -= step;
- if(dC21[1] < dC22[1]) dC21[1] += step;
- if(dC21[1] > dC22[1]) dC21[1] -= step;
- if(dC21[2] < dC22[2]) dC21[2] += step;
- if(dC21[2] > dC22[2]) dC21[2] -= step;
- dC2B = "RGB(" + dC21[0] + "," + dC21[1] + "," + dC21[2] + ")";
- daEl.style.color = dC2B;
- mode = true;
- }
- if (daColor == colorend.toLowerCase()) {
- dC21[0] = hextodec(origText.substring(0, 2));
- dC21[1] = hextodec(origText.substring(2, 4));
- dC21[2] = hextodec(origText.substring(4, 6));
- dC2B = "RGB(" + dC22[0] + "," + dC22[1] + "," + dC22[2] + ")";
- daEl.style.color = dC2B;
- clearInterval(iId)
- iId = null
- timerRunning = false
- mode = true
- }
- }
- function fade(what) {
- i++
- 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)),
- what);
- }
- 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 i
- var iId = null
- var sr, sg, sb
- var er, eg, eb
- var interval = 1
- var step = 16
- var colorstart
- var colorend
- var daEl
- var timerRunning = false
- function myfade(el,cs,ce,iv,st) {
- daEl = el
- colorstart = cs
- colorend = ce
- interval = iv
- step = st
- i = 0
- if (timerRunning) {
- clearInterval(iId)
- iId = null
- }
- var myRe = /#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i
- if (colorstart.match(myRe)) {
- sr = hextodec(RegExp.$1)
- sg = hextodec(RegExp.$2)
- sb = hextodec(RegExp.$3)
- }
- if (colorend.match(myRe)) {
- er = hextodec(RegExp.$1)
- eg = hextodec(RegExp.$2)
- eb = hextodec(RegExp.$3)
- }
- timerRunning = false;
- iId = setInterval("fade()",interval)
- timerRunning = true;
- }
- function orig(tc){
- dC21[0] = hextodec(origText.substring(0, 2));
- dC21[1] = hextodec(origText.substring(2, 4));
- dC21[2] = hextodec(origText.substring(4, 6));
- tc.style.backgroundColor = "#" + origCell;
- tc.style.borderColor = "#" + origBorder;
- tc.style.color = "#" + origText;
- }
- function cellover1(tc) {
- orig(tc);
- colorNow = "#" + origCell;
- colorTo = "#" + fadeToCell;
- myfade(tc,colorNow,colorTo,speed,steps)
- tc.style.borderColor = "#" + newBorder;
- }
- function cellout1(tc) {
- clearInterval(iId)
- tc.style.borderColor = "#" + origBorder;
- orig(tc);
- }
- //]]>
- </script>
- <style type="text/css">
- /*<![CDATA[*/
- .navA{position:absolute; left:20px; top:10px; width:120px;}
- td,.navA{border:#99aaff 1px solid; font-size:12px; font-family:Verdana,Tahoma;}
- tr{height:20px;}
- /*]]>*/
- </style>
- </head>
- <body>
- <div class="navA">
- <table cellspacing="0" width="100%" style=
- "cursor:pointer; background:#7788ff; color:#ffffff;">
- <tr>
- <td onmouseover="cellover1(this)" onmouseout=
- "cellout1(this)" onclick="window.location.href='http://www.ozzu.com'">OZZU</td>
- </tr>
- <tr>
- <td onmouseover="cellover1(this)" onmouseout=
- "cellout1(this)" onclick="window.open('http://www.google.com')">Google</td>
- </tr>
- <tr>
- <td onmouseover="cellover1(this)" onmouseout=
- "cellout1(this)" onclick="window.location.href='http://www.bigwebmaster.com'">BWM.com</td>
- </tr>
- <tr>
- <td onmouseover="cellover1(this)" onmouseout=
- "cellout1(this)" onclick="window.location.href='http://www.unflux.com'">UNFLUX.com</td>
- </tr>
- <tr>
- <td onmouseover="cellover1(this)" onmouseout=
- "cellout1(this)" onclick="window.location.href='http://www.reptilerooms.com'">Reptile Rooms</td>
- </tr>
- </table>
- </div>
- </body>
- </html>
Strong with this one, the sudo is.
- stickfigure
- Beginner


- Joined: Mar 28, 2004
- Posts: 49
- Status: Offline
- oblongintellect
- Novice


- Joined: Mar 23, 2004
- Posts: 28
- Status: Offline
- joebert
- Sledgehammer


- Joined: Feb 10, 2004
- Posts: 13455
- Loc: Florida
- Status: Offline
1, 2
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 23 posts
- Users browsing this forum: No registered users and 138 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
