technoworld

Rainbow Links For Blogger

Apr 3rd, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.59 KB | None | 0 0
  1. /************************************************************************/
  2. /* Rainbow Links Version 1.03 (2003.9.20) */
  3. /* Script updated by Dynamicdrive.com for IE6 */
  4. /* Copyright (C) 1999-2001 TAKANASHI Mizuki */
  5. /*----------------------------------------------------------------------*/
  6. /* Read it somehow even if my English text is a little wrong! ;-) */
  7. /* */
  8. /* Usage: */
  9. /* Insert '<script src="rainbow.js"></script>' into the BODY section, */
  10. /* right after the BODY tag itself, before anything else. */
  11. /* You don't need to add "onMouseover" and "onMouseout" attributes!! */
  12. /* */
  13. /* If you'd like to add effect to other texts(not link texts), then */
  14. /* add 'onmouseover="doRainbow(this);"' and */
  15. /* 'onmouseout="stopRainbow();"' to the target tags. */
  16. /* */
  17. /* This Script works with IE4,Netscape6,Mozilla browser and above only, */
  18. /* but no error occurs on other browsers. */
  19. /************************************************************************/
  20.  
  21.  
  22. ////////////////////////////////////////////////////////////////////
  23. // Setting
  24.  
  25. var rate = 20; // Increase amount(The degree of the transmutation)
  26.  
  27.  
  28. ////////////////////////////////////////////////////////////////////
  29. // Main routine
  30.  
  31. if (document.getElementById)
  32. window.onerror=new Function("return true")
  33.  
  34. var objActive; // The object which event occured in
  35. var act = 0; // Flag during the action
  36. var elmH = 0; // Hue
  37. var elmS = 128; // Saturation
  38. var elmV = 255; // Value
  39. var clrOrg; // A color before the change
  40. var TimerID; // Timer ID
  41.  
  42.  
  43. if (document.all) {
  44. document.onmouseover = doRainbowAnchor;
  45. document.onmouseout = stopRainbowAnchor;
  46. }
  47. else if (document.getElementById) {
  48. document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
  49. document.onmouseover = Mozilla_doRainbowAnchor;
  50. document.onmouseout = Mozilla_stopRainbowAnchor;
  51. }
  52.  
  53.  
  54. //=============================================================================
  55. // doRainbow
  56. // This function begins to change a color.
  57. //=============================================================================
  58. function doRainbow(obj)
  59. {
  60. if (act == 0) {
  61. act = 1;
  62. if (obj)
  63. objActive = obj;
  64. else
  65. objActive = event.srcElement;
  66. clrOrg = objActive.style.color;
  67. TimerID = setInterval("ChangeColor()",100);
  68. }
  69. }
  70.  
  71.  
  72. //=============================================================================
  73. // stopRainbow
  74. // This function stops to change a color.
  75. //=============================================================================
  76. function stopRainbow()
  77. {
  78. if (act) {
  79. objActive.style.color = clrOrg;
  80. clearInterval(TimerID);
  81. act = 0;
  82. }
  83. }
  84.  
  85.  
  86. //=============================================================================
  87. // doRainbowAnchor
  88. // This function begins to change a color. (of a anchor, automatically)
  89. //=============================================================================
  90. function doRainbowAnchor()
  91. {
  92. if (act == 0) {
  93. var obj = event.srcElement;
  94. while (obj.tagName != 'A' && obj.tagName != 'BODY') {
  95. obj = obj.parentElement;
  96. if (obj.tagName == 'A' || obj.tagName == 'BODY')
  97. break;
  98. }
  99.  
  100. if (obj.tagName == 'A' && obj.href != '') {
  101. objActive = obj;
  102. act = 1;
  103. clrOrg = objActive.style.color;
  104. TimerID = setInterval("ChangeColor()",100);
  105. }
  106. }
  107. }
  108.  
  109.  
  110. //=============================================================================
  111. // stopRainbowAnchor
  112. // This function stops to change a color. (of a anchor, automatically)
  113. //=============================================================================
  114. function stopRainbowAnchor()
  115. {
  116. if (act) {
  117. if (objActive.tagName == 'A') {
  118. objActive.style.color = clrOrg;
  119. clearInterval(TimerID);
  120. act = 0;
  121. }
  122. }
  123. }
  124.  
  125.  
  126. //=============================================================================
  127. // Mozilla_doRainbowAnchor(for Netscape6 and Mozilla browser)
  128. // This function begins to change a color. (of a anchor, automatically)
  129. //=============================================================================
  130. function Mozilla_doRainbowAnchor(e)
  131. {
  132. if (act == 0) {
  133. obj = e.target;
  134. while (obj.nodeName != 'A' && obj.nodeName != 'BODY') {
  135. obj = obj.parentNode;
  136. if (obj.nodeName == 'A' || obj.nodeName == 'BODY')
  137. break;
  138. }
  139.  
  140. if (obj.nodeName == 'A' && obj.href != '') {
  141. objActive = obj;
  142. act = 1;
  143. clrOrg = obj.style.color;
  144. TimerID = setInterval("ChangeColor()",100);
  145. }
  146. }
  147. }
  148.  
  149.  
  150. //=============================================================================
  151. // Mozilla_stopRainbowAnchor(for Netscape6 and Mozilla browser)
  152. // This function stops to change a color. (of a anchor, automatically)
  153. //=============================================================================
  154. function Mozilla_stopRainbowAnchor(e)
  155. {
  156. if (act) {
  157. if (objActive.nodeName == 'A') {
  158. objActive.style.color = clrOrg;
  159. clearInterval(TimerID);
  160. act = 0;
  161. }
  162. }
  163. }
  164.  
  165.  
  166. //=============================================================================
  167. // Change Color
  168. // This function changes a color actually.
  169. //=============================================================================
  170. function ChangeColor()
  171. {
  172. objActive.style.color = makeColor();
  173. }
  174.  
  175.  
  176. //=============================================================================
  177. // makeColor
  178. // This function makes rainbow colors.
  179. //=============================================================================
  180. function makeColor()
  181. {
  182. // Don't you think Color Gamut to look like Rainbow?
  183.  
  184. // HSVtoRGB
  185. if (elmS == 0) {
  186. elmR = elmV; elmG = elmV; elmB = elmV;
  187. }
  188. else {
  189. t1 = elmV;
  190. t2 = (255 - elmS) * elmV / 255;
  191. t3 = elmH % 60;
  192. t3 = (t1 - t2) * t3 / 60;
  193.  
  194. if (elmH < 60) {
  195. elmR = t1; elmB = t2; elmG = t2 + t3;
  196. }
  197. else if (elmH < 120) {
  198. elmG = t1; elmB = t2; elmR = t1 - t3;
  199. }
  200. else if (elmH < 180) {
  201. elmG = t1; elmR = t2; elmB = t2 + t3;
  202. }
  203. else if (elmH < 240) {
  204. elmB = t1; elmR = t2; elmG = t1 - t3;
  205. }
  206. else if (elmH < 300) {
  207. elmB = t1; elmG = t2; elmR = t2 + t3;
  208. }
  209. else if (elmH < 360) {
  210. elmR = t1; elmG = t2; elmB = t1 - t3;
  211. }
  212. else {
  213. elmR = 0; elmG = 0; elmB = 0;
  214. }
  215. }
  216.  
  217. elmR = Math.floor(elmR).toString(16);
  218. elmG = Math.floor(elmG).toString(16);
  219. elmB = Math.floor(elmB).toString(16);
  220. if (elmR.length == 1) elmR = "0" + elmR;
  221. if (elmG.length == 1) elmG = "0" + elmG;
  222. if (elmB.length == 1) elmB = "0" + elmB;
  223.  
  224. elmH = elmH + rate;
  225. if (elmH >= 360)
  226. elmH = 0;
  227.  
  228. return '#' + elmR + elmG + elmB;
  229. }
Advertisement
Add Comment
Please, Sign In to add comment