Pinkey

Bubble Cursor

Dec 23rd, 2012
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. <script type="text/javascript">
  2. // <![CDATA[
  3. var colours=new Array("#a6f", "#60f", "#60f", "#a6f", "#ccc"); // colours for top, right, bottom and left borders and background of bubbles
  4. var bubbles=66; // maximum number of bubbles on screen
  5.  
  6. /****************************
  7. * JavaScript Bubble Cursor *
  8. *(c)2010-12 mf2fm web-design*
  9. * http://www.mf2fm.com/rv *
  10. * DON'T EDIT BELOW THIS BOX *
  11. ****************************/
  12. var x=ox=400;
  13. var y=oy=300;
  14. var swide=800;
  15. var shigh=600;
  16. var sleft=sdown=0;
  17. var bubb=new Array();
  18. var bubbx=new Array();
  19. var bubby=new Array();
  20. var bubbs=new Array();
  21. var sploosh=false;
  22.  
  23. function addLoadEvent(funky) {
  24. var oldonload=window.onload;
  25. if (typeof(oldonload)!='function') window.onload=funky;
  26. else window.onload=function() {
  27. if (oldonload) oldonload();
  28. funky();
  29. }
  30. }
  31.  
  32. addLoadEvent(buble);
  33.  
  34. function buble() { if (document.getElementById) {
  35. var i, rats, div;
  36. for (i=0; i<bubbles; i++) {
  37. rats=createDiv("3px", "3px");
  38. rats.style.visibility="hidden";
  39.  
  40. div=createDiv("auto", "auto");
  41. rats.appendChild(div);
  42. div=div.style;
  43. div.top="1px";
  44. div.left="0px";
  45. div.bottom="1px";
  46. div.right="0px";
  47. div.borderLeft="1px solid "+colours[3];
  48. div.borderRight="1px solid "+colours[1];
  49.  
  50. div=createDiv("auto", "auto");
  51. rats.appendChild(div);
  52. div=div.style;
  53. div.top="0px";
  54. div.left="1px";
  55. div.right="1px";
  56. div.bottom="0px"
  57. div.borderTop="1px solid "+colours[0];
  58. div.borderBottom="1px solid "+colours[2];
  59.  
  60. div=createDiv("auto", "auto");
  61. rats.appendChild(div);
  62. div=div.style;
  63. div.left="1px";
  64. div.right="1px";
  65. div.bottom="1px";
  66. div.top="1px";
  67. div.backgroundColor=colours[4];
  68. if (navigator.appName=="Microsoft Internet Explorer") div.filter="alpha(opacity=50)";
  69. else div.opacity=0.5;
  70. document.body.appendChild(rats);
  71. bubb[i]=rats.style;
  72. }
  73. set_scroll();
  74. set_width();
  75. bubble();
  76. }}
  77.  
  78. function bubble() {
  79. var c;
  80. if (Math.abs(x-ox)>1 || Math.abs(y-oy)>1) {
  81. ox=x;
  82. oy=y;
  83. for (c=0; c<bubbles; c++) if (!bubby[c]) {
  84. bubb[c].left=(bubbx[c]=x)+"px";
  85. bubb[c].top=(bubby[c]=y)+"px";
  86. bubb[c].width="3px";
  87. bubb[c].height="3px"
  88. bubb[c].visibility="visible";
  89. bubbs[c]=3;
  90. break;
  91. }
  92. }
  93. for (c=0; c<bubbles; c++) if (bubby[c]) update_bubb(c);
  94. setTimeout("bubble()", 40);
  95. }
  96.  
  97. document.onmousedown=splash;
  98. document.onmouseup=function(){clearTimeout(sploosh);};
  99.  
  100. function splash() {
  101. ox=-1;
  102. oy=-1;
  103. sploosh=setTimeout('splash()', 100);
  104. }
  105.  
  106. function update_bubb(i) {
  107. if (bubby[i]) {
  108. bubby[i]-=bubbs[i]/2+i%2;
  109. bubbx[i]+=(i%5-2)/5;
  110. if (bubby[i]>sdown && bubbx[i]>sleft && bubbx[i]<sleft+swide+bubbs[i]) {
  111. if (Math.random()<bubbs[i]/shigh*2 && bubbs[i]++<8) {
  112. bubb[i].width=bubbs[i]+"px";
  113. bubb[i].height=bubbs[i]+"px";
  114. }
  115. bubb[i].top=bubby[i]+"px";
  116. bubb[i].left=bubbx[i]+"px";
  117. }
  118. else {
  119. bubb[i].visibility="hidden";
  120. bubby[i]=0;
  121. return;
  122. }
  123. }
  124. }
  125.  
  126. document.onmousemove=mouse;
  127. function mouse(e) {
  128. if (e) {
  129. y=e.pageY;
  130. x=e.pageX;
  131. }
  132. else {
  133. set_scroll();
  134. y=event.y+sdown;
  135. x=event.x+sleft;
  136. }
  137. }
  138.  
  139. window.onresize=set_width;
  140. function set_width() {
  141. var sw_min=999999;
  142. var sh_min=999999;
  143. if (document.documentElement && document.documentElement.clientWidth) {
  144. if (document.documentElement.clientWidth>0) sw_min=document.documentElement.clientWidth;
  145. if (document.documentElement.clientHeight>0) sh_min=document.documentElement.clientHeight;
  146. }
  147. if (typeof(self.innerWidth)=='number' && self.innerWidth) {
  148. if (self.innerWidth>0 && self.innerWidth<sw_min) sw_min=self.innerWidth;
  149. if (self.innerHeight>0 && self.innerHeight<sh_min) sh_min=self.innerHeight;
  150. }
  151. if (document.body.clientWidth) {
  152. if (document.body.clientWidth>0 && document.body.clientWidth<sw_min) sw_min=document.body.clientWidth;
  153. if (document.body.clientHeight>0 && document.body.clientHeight<sh_min) sh_min=document.body.clientHeight;
  154. }
  155. if (sw_min==999999 || sh_min==999999) {
  156. sw_min=800;
  157. sh_min=600;
  158. }
  159. swide=sw_min;
  160. shigh=sh_min;
  161. }
  162.  
  163. window.onscroll=set_scroll;
  164. function set_scroll() {
  165. if (typeof(self.pageYOffset)=='number') {
  166. sdown=self.pageYOffset;
  167. sleft=self.pageXOffset;
  168. }
  169. else if (document.body && (document.body.scrollTop || document.body.scrollLeft)) {
  170. sdown=document.body.scrollTop;
  171. sleft=document.body.scrollLeft;
  172. }
  173. else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
  174. sleft=document.documentElement.scrollLeft;
  175. sdown=document.documentElement.scrollTop;
  176. }
  177. else {
  178. sdown=0;
  179. sleft=0;
  180. }
  181. }
  182.  
  183. function createDiv(height, width) {
  184. var div=document.createElement("div");
  185. div.style.position="absolute";
  186. div.style.height=height;
  187. div.style.width=width;
  188. div.style.overflow="hidden";
  189. div.style.backgroundColor="transparent";
  190. return (div);
  191. }
  192. // ]]>
  193. </script>
Advertisement
Add Comment
Please, Sign In to add comment