Advertisement
kyujouz

rainbow hover~

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