onMouseover cell color change...?

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post March 30th, 2004, 12:23 pm

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 :D
Strong with this one, the sudo is.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post March 30th, 2004, 12:23 pm

  • oblongintellect
  • Novice
  • Novice
  • No Avatar
  • Joined: Mar 23, 2004
  • Posts: 28
  • Status: Offline

Post March 30th, 2004, 2:35 pm

You gotta let me know! This would make an excellent "all in one" script for my site!
  • stickfigure
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Mar 28, 2004
  • Posts: 49
  • Status: Offline

Post March 30th, 2004, 5:22 pm

thank you Nunzio390! it was exactly what i was looking for.

however, i can get it to work externally but like the others, the link hover cancels it out. (i am also using your fade script)

if anyone can figure out a solution please post it!
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post March 30th, 2004, 10:48 pm

Edit: Found time to play with it a little more :D
[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>
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content=
  6. "text/html; charset=us-ascii" />
  7. <title>cross-fade</title>
  8. <script language="javascript" type="text/javascript">
  9. //<![CDATA[
  10. var speed = 40; // milliseconds between each step of transition
  11. var steps = 20; // amount to + or - by each step of transition
  12. var fadeToText = "7788ff"; // color for text to fade to
  13. var fadeToCell = "f0f0f0"; // color for cell to fade to
  14. var origText = "ffffff"; // original text color
  15. var origCell = "7788ff"; // original cell color
  16. var newBorder = "56789a"; // border hover color
  17. var origBorder = "99aaff"; // original border color
  18. dC21 = new Array(hextodec(origText.substring(0, 2)),hextodec(origText.substring(2, 4)),hextodec(origText.substring(4, 6)));
  19. dC22 = new Array(hextodec(fadeToText.substring(0, 2)),hextodec(fadeToText.substring(2, 4)),hextodec(fadeToText.substring(4, 6)));
  20. function makearray(n) {
  21.  this.length = n;
  22.  for(var i = 1; i <= n; i++)
  23.   this[i] = 0;
  24.  return this;
  25. }
  26. function hex(i) {
  27.  if (i < 0)  return "00";
  28.  else if (i > 255) return "ff";
  29.  else   return "" + hexa[Math.floor(i/16)] + hexa[i%16];
  30. }
  31. function hexnumtodec(hexchar) {
  32.  if (parseInt(hexchar) == hexchar) return Number(hexchar)
  33.  hexchar = hexchar.toUpperCase()
  34.  switch (hexchar) {
  35.   case 'A': return 10; break;
  36.   case 'B': return 11; break;
  37.   case 'C': return 12; break;
  38.   case 'D': return 13; break;
  39.   case 'E': return 14; break;
  40.   case 'F': return 15; break;
  41.  }
  42. }
  43. function hextodec(daHex) {
  44.  var daDec = Number((16 * hexnumtodec(daHex.substring(0,1))) + hexnumtodec(daHex.substring(1,2)))
  45.  return daDec
  46. }
  47. function convert2Dec(hex)
  48.  {
  49.   var rgb = new Array();
  50.   for (var u = 0; u < 3; u++)
  51.    rgb[u] = parseInt(hex.substring(u*2, u*2+2), 16);
  52.   return rgb;
  53.  }
  54. mode = true;
  55. function setColor(r,g,b,what) {
  56.  var hr = hex(r); var hg = hex(g); var hb = hex(b);
  57.  var daColor = "#"+hr+hg+hb
  58.  if(mode){
  59.       daEl.style.backgroundColor = daColor;
  60.       mode = false;
  61.  }
  62.  else{
  63.      if(dC21[0] < dC22[0]) dC21[0] += step;
  64.      if(dC21[0] > dC22[0]) dC21[0] -= step;
  65.      if(dC21[1] < dC22[1]) dC21[1] += step;
  66.      if(dC21[1] > dC22[1]) dC21[1] -= step;
  67.      if(dC21[2] < dC22[2]) dC21[2] += step;
  68.      if(dC21[2] > dC22[2]) dC21[2] -= step;
  69.      dC2B = "RGB(" + dC21[0] + "," + dC21[1] + "," + dC21[2] + ")";
  70.      daEl.style.color = dC2B;
  71.      mode = true;
  72.  }   
  73.  if (daColor == colorend.toLowerCase()) {
  74.   dC21[0] = hextodec(origText.substring(0, 2));
  75.   dC21[1] = hextodec(origText.substring(2, 4));
  76.   dC21[2] = hextodec(origText.substring(4, 6));
  77.   dC2B = "RGB(" + dC22[0] + "," + dC22[1] + "," + dC22[2] + ")";
  78.   daEl.style.color = dC2B;
  79.   clearInterval(iId)
  80.   iId = null
  81.   timerRunning = false
  82.   mode = true
  83.  }
  84. }
  85. function fade(what) {
  86.  i++
  87.  setColor(
  88.   Math.floor(sr * ((step-i)/step) + er * (i/step)),
  89.   Math.floor(sg * ((step-i)/step) + eg * (i/step)),
  90.   Math.floor(sb * ((step-i)/step) + eb * (i/step)),
  91.   what);
  92. }
  93. hexa = new makearray(16);
  94. for(var i = 0; i < 10; i++)
  95.  hexa[i] = i;
  96. hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
  97. hexa[13]="d"; hexa[14]="e"; hexa[15]="f";
  98. var i
  99. var iId = null
  100. var sr, sg, sb
  101. var er, eg, eb
  102. var interval = 1
  103. var step = 16
  104. var colorstart
  105. var colorend
  106. var daEl
  107. var timerRunning = false
  108. function myfade(el,cs,ce,iv,st) {
  109.  daEl = el
  110.  colorstart = cs
  111.  colorend = ce
  112.  interval = iv
  113.  step = st
  114.  i = 0
  115.  if (timerRunning) {
  116.   clearInterval(iId)
  117.   iId = null
  118.  }
  119.  var myRe = /#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i
  120.  if (colorstart.match(myRe)) {
  121.   sr = hextodec(RegExp.$1)
  122.   sg = hextodec(RegExp.$2)
  123.   sb = hextodec(RegExp.$3)
  124.  }
  125.  if (colorend.match(myRe)) {
  126.   er = hextodec(RegExp.$1)
  127.   eg = hextodec(RegExp.$2)
  128.   eb = hextodec(RegExp.$3)
  129.  }
  130.  timerRunning = false;
  131.  iId = setInterval("fade()",interval)
  132.  timerRunning = true;
  133. }
  134. function orig(tc){
  135.      dC21[0] = hextodec(origText.substring(0, 2));
  136.      dC21[1] = hextodec(origText.substring(2, 4));
  137.      dC21[2] = hextodec(origText.substring(4, 6));
  138.      tc.style.backgroundColor = "#" + origCell;
  139.      tc.style.borderColor = "#" + origBorder;
  140.      tc.style.color = "#" + origText;
  141. }
  142. function cellover1(tc) {
  143.  orig(tc);
  144.  colorNow = "#" + origCell;
  145.  colorTo = "#" + fadeToCell;
  146.  myfade(tc,colorNow,colorTo,speed,steps)
  147.  tc.style.borderColor = "#" + newBorder;
  148. }
  149. function cellout1(tc) {
  150.  clearInterval(iId)
  151.  tc.style.borderColor = "#" + origBorder;
  152.  orig(tc);
  153. }
  154. //]]>
  155. </script>
  156. <style type="text/css">
  157. /*<![CDATA[*/
  158. .navA{position:absolute; left:20px; top:10px; width:120px;}
  159. td,.navA{border:#99aaff 1px solid; font-size:12px; font-family:Verdana,Tahoma;}
  160. tr{height:20px;}
  161. /*]]>*/
  162. </style>
  163. </head>
  164. <body>
  165. <div class="navA">
  166. <table cellspacing="0" width="100%" style=
  167. "cursor:pointer; background:#7788ff; color:#ffffff;">
  168. <tr>
  169. <td onmouseover="cellover1(this)" onmouseout=
  170. "cellout1(this)" onclick="window.location.href='http://www.ozzu.com'">OZZU</td>
  171. </tr>
  172. <tr>
  173. <td onmouseover="cellover1(this)" onmouseout=
  174. "cellout1(this)" onclick="window.open('http://www.google.com')">Google</td>
  175. </tr>
  176. <tr>
  177. <td onmouseover="cellover1(this)" onmouseout=
  178. "cellout1(this)" onclick="window.location.href='http://www.bigwebmaster.com'">BWM.com</td>
  179. </tr>
  180. <tr>
  181. <td onmouseover="cellover1(this)" onmouseout=
  182. "cellout1(this)" onclick="window.location.href='http://www.unflux.com'">UNFLUX.com</td>
  183. </tr>
  184. <tr>
  185. <td onmouseover="cellover1(this)" onmouseout=
  186. "cellout1(this)" onclick="window.location.href='http://www.reptilerooms.com'">Reptile Rooms</td>
  187. </tr>
  188. </table>
  189. </div>
  190. </body>
  191. </html>
Strong with this one, the sudo is.
  • stickfigure
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Mar 28, 2004
  • Posts: 49
  • Status: Offline

Post March 30th, 2004, 11:31 pm

still getting a "'style' is null or not an object " error :shock:
  • oblongintellect
  • Novice
  • Novice
  • No Avatar
  • Joined: Mar 23, 2004
  • Posts: 28
  • Status: Offline

Post March 31st, 2004, 1:53 am

That's impressive. I'll play with it some and see what I can come up with. Thx joebert! :D
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post March 31st, 2004, 7:30 pm

Found time to play with that script a little more :D I just edited my original post.
Strong with this one, the sudo is.
  • oblongintellect
  • Novice
  • Novice
  • No Avatar
  • Joined: Mar 23, 2004
  • Posts: 28
  • Status: Offline

Post April 1st, 2004, 8:28 pm

That is really good! I'm definetly going to use it thanks joebert!

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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.