emmysthemes

rainbow links

Nov 27th, 2012
990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. <script type='text/javascript'>
  2. var rate = 20;
  3. if (document.getElementById)
  4. window.onerror=new Function("return true")
  5. var objActive; // The object which event occured in
  6. var act = 0; // Flag during the action
  7. var elmH = 0; // Hue
  8. var elmS = 128; // Saturation
  9. var elmV = 255; // Value
  10. var clrOrg; // A color before the change
  11. var TimerID; // Timer ID
  12. if (document.all) {
  13. document.onmouseover = doRainbowAnchor;
  14. document.onmouseout = stopRainbowAnchor;
  15. }
  16. else if (document.getElementById) {
  17. document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
  18. document.onmouseover = Mozilla_doRainbowAnchor;
  19. document.onmouseout = Mozilla_stopRainbowAnchor;
  20. }
  21. function doRainbow(obj)
  22. {
  23. if (act == 0) {
  24. act = 1;
  25. if (obj)
  26. objActive = obj;
  27. else
  28. objActive = event.srcElement;
  29. clrOrg = objActive.style.color;
  30. TimerID = setInterval("ChangeColor()",100);
  31. }
  32. }
  33.  
  34. function stopRainbow()
  35. {
  36. if (act) {
  37. objActive.style.color = clrOrg;
  38. clearInterval(TimerID);
  39. act = 0;
  40. }
  41. }
  42.  
  43. function doRainbowAnchor()
  44. {
  45. if (act == 0) {
  46. var obj = event.srcElement;
  47. while (obj.tagName != 'A' && obj.tagName != 'BODY') {
  48. obj = obj.parentElement;
  49. if (obj.tagName == 'A' || obj.tagName == 'BODY')
  50. break;
  51. }
  52. if (obj.tagName == 'A' && obj.href != '') {
  53. objActive = obj;
  54. act = 1;
  55. clrOrg = objActive.style.color;
  56. TimerID = setInterval("ChangeColor()",100);
  57. }
  58. }
  59. }
  60.  
  61. function stopRainbowAnchor()
  62. {
  63. if (act) {
  64. if (objActive.tagName == 'A') {
  65. objActive.style.color = clrOrg;
  66. clearInterval(TimerID);
  67. act = 0;
  68. }
  69. }
  70. }
  71.  
  72. function Mozilla_doRainbowAnchor(e)
  73. {
  74. if (act == 0) {
  75. obj = e.target;
  76. while (obj.nodeName != 'A' && obj.nodeName != 'BODY') {
  77. obj = obj.parentNode;
  78. if (obj.nodeName == 'A' || obj.nodeName == 'BODY')
  79. break;
  80. }
  81. if (obj.nodeName == 'A' && obj.href != '') {
  82. objActive = obj;
  83. act = 1;
  84. clrOrg = obj.style.color;
  85. TimerID = setInterval("ChangeColor()",100);
  86. }
  87. }
  88. }
  89.  
  90. function Mozilla_stopRainbowAnchor(e)
  91. {
  92. if (act) {
  93. if (objActive.nodeName == 'A') {
  94. objActive.style.color = clrOrg;
  95. clearInterval(TimerID);
  96. act = 0;
  97. }
  98. }
  99. }
  100.  
  101. function ChangeColor()
  102. {
  103. objActive.style.color = makeColor();
  104. }
  105.  
  106. function makeColor()
  107. {
  108. // Don't you think Color Gamut to look like Rainbow?
  109. // HSVtoRGB
  110. if (elmS == 0) {
  111. elmR = elmV; elmG = elmV; elmB = elmV;
  112. }
  113. else {
  114. t1 = elmV;
  115. t2 = (255 - elmS) * elmV / 255;
  116. t3 = elmH % 60;
  117. t3 = (t1 - t2) * t3 / 60;
  118. if (elmH < 60) {
  119. elmR = t1; elmB = t2; elmG = t2 + t3;
  120. }
  121. else if (elmH < 120) {
  122. elmG = t1; elmB = t2; elmR = t1 - t3;
  123. }
  124. else if (elmH < 180) {
  125. elmG = t1; elmR = t2; elmB = t2 + t3;
  126. }
  127. else if (elmH < 240) {
  128. elmB = t1; elmR = t2; elmG = t1 - t3;
  129. }
  130. else if (elmH < 300) {
  131. elmB = t1; elmG = t2; elmR = t2 + t3;
  132. }
  133. else if (elmH < 360) {
  134. elmR = t1; elmG = t2; elmB = t1 - t3;
  135. }
  136. else {
  137. elmR = 0; elmG = 0; elmB = 0;
  138. }
  139. }
  140. elmR = Math.floor(elmR).toString(16);
  141. elmG = Math.floor(elmG).toString(16);
  142. elmB = Math.floor(elmB).toString(16);
  143. if (elmR.length == 1) elmR = "0" + elmR;
  144. if (elmG.length == 1) elmG = "0" + elmG;
  145. if (elmB.length == 1) elmB = "0" + elmB;
  146. elmH = elmH + rate;
  147. if (elmH >= 360)
  148. elmH = 0;
  149. return '#' + elmR + elmG + elmB;
  150. }
  151. //]]>
  152. </script>
  153. //*tutorial by harrychristmas*//
Advertisement
Add Comment
Please, Sign In to add comment