943,577 Members | Top Members by Rank

Ad:
Apr 15th, 2007
0

Need help with js mouseover

Expand Post »
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
Similar Threads
Reputation Points: 9
Solved Threads: 0
Newbie Poster
connor4312 is offline Offline
16 posts
since Apr 2007
Apr 16th, 2007
-1

Re: Need help with js mouseover

Any plpz???
Reputation Points: 9
Solved Threads: 0
Newbie Poster
connor4312 is offline Offline
16 posts
since Apr 2007
Apr 17th, 2007
0

Re: Need help with js mouseover

I think it may have a problem with a onmouseover sidemeanu
Reputation Points: 9
Solved Threads: 0
Newbie Poster
connor4312 is offline Offline
16 posts
since Apr 2007
Apr 24th, 2007
0

Re: Need help with js mouseover

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.
Reputation Points: 9
Solved Threads: 0
Newbie Poster
connor4312 is offline Offline
16 posts
since Apr 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in HTML and CSS Forum Timeline: Open in window, not frame
Next Thread in HTML and CSS Forum Timeline: I want to learn web development





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC