Need help with js mouseover

Reply

Join Date: Apr 2007
Posts: 16
Reputation: connor4312 is an unknown quantity at this point 
Solved Threads: 0
connor4312's Avatar
connor4312 connor4312 is offline Offline
Newbie Poster

Need help with js mouseover

 
0
  #1
Apr 15th, 2007
HI! im having trouble with a rainbow mouseover, it only works on the first like it goes over. The code is here:

<script src="rainbow.js"></script>

with the js being;

HTML and CSS Syntax (Toggle Plain Text)
  1. ////////////////////////////////////////////////////////////////////
  2. // Setting
  3. var rate = 20;
  4. ////////////////////////////////////////////////////////////////////
  5. // Main routine
  6. if (document.getElementById)
  7. window.onerror=new Function("return true")
  8. var objActive; // The object which event occured in
  9. var act = 0; // Flag during the action
  10. var elmH = 0; // Hue
  11. var elmS = 128; // Saturation
  12. var elmV = 255; // Value
  13. var clrOrg; // A color before the change
  14. var TimerID; // Timer ID
  15.  
  16. if (document.all) {
  17. document.onmouseover = doRainbowAnchor;
  18. document.onmouseout = stopRainbowAnchor;
  19. }
  20. else if (document.getElementById) {
  21. document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
  22. document.onmouseover = Mozilla_doRainbowAnchor;
  23. document.onmouseout = Mozilla_stopRainbowAnchor;
  24. }
  25.  
  26. function doRainbow(obj)
  27. {
  28. if (act == 0) {
  29. act = 1;
  30. if (obj)
  31. objActive = obj;
  32. else
  33. objActive = event.srcElement;
  34. clrOrg = objActive.style.color;
  35. TimerID = setInterval("ChangeColor()",100);
  36. }
  37. }
  38.  
  39. function stopRainbow()
  40. {
  41. if (act) {
  42. objActive.style.color = clrOrg;
  43. clearInterval(TimerID);
  44. act = 0;
  45. }
  46. }
  47.  
  48. {
  49. if (act == 0) {
  50. var obj = event.srcElement;
  51. while (obj.tagName != 'A' && obj.tagName != 'BODY') {
  52. obj = obj.parentElement;
  53. if (obj.tagName == 'A' || obj.tagName == 'BODY')
  54. break;
  55. }
  56. if (obj.tagName == 'A' && obj.href != '') {
  57. objActive = obj;
  58. act = 1;
  59. clrOrg = objActive.style.color;
  60. TimerID = setInterval("ChangeColor()",100);
  61. }
  62. }
  63. }
  64.  
  65. {
  66. if (act) {
  67. if (objActive.tagName == 'A') {
  68. objActive.style.color = clrOrg;
  69. clearInterval(TimerID);
  70. act = 0;
  71. }
  72. }
  73. }
  74.  
  75. function Mozilla_doRainbowAnchor(e)
  76. {
  77. if (act == 0) {
  78. obj = e.target;
  79. while (obj.nodeName != 'A' && obj.nodeName != 'BODY') {
  80. obj = obj.parentNode;
  81. if (obj.nodeName == 'A' || obj.nodeName == 'BODY')
  82. break;
  83. }
  84. if (obj.nodeName == 'A' && obj.href != '') {
  85. objActive = obj;
  86. act = 1;
  87. clrOrg = obj.style.color;
  88. TimerID = setInterval("ChangeColor()",100);
  89. }
  90. }
  91. }
  92.  
  93. function Mozilla_stopRainbowAnchor(e)
  94. {
  95. if (act) {
  96. if (objActive.nodeName == 'A') {
  97. objActive.style.color = clrOrg;
  98. clearInterval(TimerID);
  99. act = 0;
  100. }
  101. }
  102. }
  103.  
  104.  
  105. function ChangeColor()
  106. {
  107. objActive.style.color = makeColor();
  108. }
  109.  
  110. //=============================================================================
  111. // makeColor
  112. // This function makes rainbow colors.
  113. //=============================================================================
  114. function makeColor()
  115. {
  116. // Don't you think Color Gamut to look like Rainbow?
  117. // HSVtoRGB
  118. if (elmS == 0) {
  119. elmR = elmV; elmG = elmV; elmB = elmV;
  120. }
  121. else {
  122. t1 = elmV;
  123. t2 = (255 - elmS) * elmV / 255;
  124. t3 = elmH % 60;
  125. t3 = (t1 - t2) * t3 / 60;
  126. if (elmH < 60) {
  127. elmR = t1; elmB = t2; elmG = t2 + t3;
  128. }
  129. else if (elmH < 120) {
  130. elmG = t1; elmB = t2; elmR = t1 - t3;
  131. }
  132. else if (elmH < 180) {
  133. elmG = t1; elmR = t2; elmB = t2 + t3;
  134. }
  135. else if (elmH < 240) {
  136. elmB = t1; elmR = t2; elmG = t1 - t3;
  137. }
  138. else if (elmH < 300) {
  139. elmB = t1; elmG = t2; elmR = t2 + t3;
  140. }
  141. else if (elmH < 360) {
  142. elmR = t1; elmG = t2; elmB = t1 - t3;
  143. }
  144. else {
  145. elmR = 0; elmG = 0; elmB = 0;
  146. }
  147. }
  148. elmR = Math.floor(elmR).toString(16);
  149. elmG = Math.floor(elmG).toString(16);
  150. elmB = Math.floor(elmB).toString(16);
  151. if (elmR.length == 1) elmR = "0" + elmR;
  152. if (elmG.length == 1) elmG = "0" + elmG;
  153. if (elmB.length == 1) elmB = "0" + elmB;
  154. elmH = elmH + rate;
  155. if (elmH >= 360)
  156. elmH = 0;
  157. return '#' + elmR + elmG + elmB;
  158. }
Last edited by stymiee; Apr 15th, 2007 at 11:13 am. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 16
Reputation: connor4312 is an unknown quantity at this point 
Solved Threads: 0
connor4312's Avatar
connor4312 connor4312 is offline Offline
Newbie Poster

Re: Need help with js mouseover

 
-1
  #2
Apr 16th, 2007
Any plpz???
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 16
Reputation: connor4312 is an unknown quantity at this point 
Solved Threads: 0
connor4312's Avatar
connor4312 connor4312 is offline Offline
Newbie Poster

Re: Need help with js mouseover

 
0
  #3
Apr 17th, 2007
I think it may have a problem with a onmouseover sidemeanu
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 16
Reputation: connor4312 is an unknown quantity at this point 
Solved Threads: 0
connor4312's Avatar
connor4312 connor4312 is offline Offline
Newbie Poster

Re: Need help with js mouseover

 
0
  #4
Apr 24th, 2007
Wait, I think it may be hat it has a body onload thing, and would it stp if there was 2 of them? My sorse is pretty unorginized, so i dont know.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the HTML and CSS Forum
Thread Tools Search this Thread



Tag cloud for HTML and CSS
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC