Advertisement
elsaofarendelle

blobs in a jar

Jun 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1.  
  2. <script type="text/javascript">
  3. // <![CDATA[
  4. var colour="#FFF"; // what colour are the blobs
  5. var speed=66; // speed of animation, lower is faster
  6. var blobs=10; // how many blobs are in the jar
  7. var charc='❄'; // a blob - can be changed to charc='hello' or charc='*' for a different effect
  8.  
  9. /***************************\
  10. * Blobs in a Jar Effect *
  11. *(c)2012-13 mf2fm web-design*
  12. * http://www.mf2fm.com/rv *
  13. * DON'T EDIT BELOW THIS BOX *
  14. \***************************/
  15.  
  16. var div;
  17. var xpos=new Array();
  18. var ypos=new Array();
  19. var zpos=new Array();
  20. var dx=new Array();
  21. var dy=new Array();
  22. var dz=new Array();
  23. var blob=new Array();
  24. var swide=800;
  25. var shigh=600;
  26. var ie_version=(navigator.appVersion.indexOf("MSIE")!=-1)?parseFloat(navigator.appVersion.split("MSIE")[1]):false;
  27.  
  28. function addLoadEvent(funky) {
  29. var oldonload=window.onload;
  30. if (typeof(oldonload)!='function') window.onload=funky;
  31. else window.onload=function() {
  32. if (oldonload) oldonload();
  33. funky();
  34. }
  35. }
  36.  
  37. addLoadEvent(fill_the_jar);
  38.  
  39. function fill_the_jar() {
  40. var i, dvs;
  41. div=document.createElement('div');
  42. dvs=div.style;
  43. dvs.position='fixed';
  44. dvs.left='0px';
  45. dvs.top='0px';
  46. dvs.width='1px';
  47. dvs.height='1px';
  48. document.body.appendChild(div);
  49. set_width();
  50. for (i=0; i<blobs; i++) {
  51. add_blob(i);
  52. jamjar(i);
  53. }
  54. }
  55.  
  56. function add_blob(ref) {
  57. var dv, sy;
  58. dv=document.createElement('div');
  59. sy=dv.style;
  60. sy.position='absolute';
  61. sy.textAlign='center';
  62. if (ie_version && ie_version<10) {
  63. sy.fontSize="10px";
  64. sy.width="100px";
  65. sy.height="100px";
  66. sy.paddingTop="40px";
  67. sy.color=colour;
  68. dv.appendChild(document.createTextNode(charc));
  69. }
  70. else if (ie_version) {
  71. sy.fontSize="1px";
  72. sy.width="0px";
  73. sy.height="0px";
  74. }
  75. else {
  76. dv.appendChild(document.createTextNode(charc));
  77. sy.color='rgba(0,0,0,0)';
  78. }
  79. ypos[ref]=Math.floor(shigh*Math.random());
  80. dy[ref]=(0.5+Math.random())*(Math.random()>.5?2:-2);
  81. xpos[ref]=Math.floor(swide*Math.random());
  82. dx[ref]=(0.5+Math.random())*(Math.random()>.5?2:-2);
  83. zpos[ref]=Math.random()*20;
  84. dz[ref]=(0.5+Math.random())*(Math.random()>.5?.5:-.5);
  85. blob[ref]=dv;
  86. div.appendChild(blob[ref]);
  87. set_blob(ref);
  88. }
  89.  
  90. function rejig(ref, xy) {
  91. if (xy=='y') {
  92. dx[ref]=(0.5+Math.random())*sign(dx[ref]);
  93. dy[ref]=(0.5+Math.random())*-sign(dy[ref]);
  94. }
  95. else {
  96. dx[ref]=(0.5+Math.random())*-sign(dx[ref]);
  97. dy[ref]=(0.5+Math.random())*sign(dy[ref]);
  98. }
  99. }
  100.  
  101. function sign(a) {
  102. if (a<0) return (-2);
  103. else if (a>0) return (2);
  104. else return (0);
  105. }
  106.  
  107. function set_blob(ref) {
  108. var sy;
  109. sy=blob[ref].style;
  110. sy.top=ypos[ref]+'px';
  111. sy.left=xpos[ref]+'px';
  112. if (ie_version && ie_version<10) {
  113. sy.filter="glow(color="+colour+",strength="+zpos[ref]+")";
  114. sy.fontSize=30-zpos[ref]+"px";
  115. }
  116. else if (ie_version) {
  117. sy.boxShadow="0px 0px 40px "+zpos[ref]+"px "+colour;
  118. }
  119. else {
  120. sy.textShadow=colour+' 0px 0px '+zpos[ref]+'px';
  121. sy.fontSize=40+zpos[ref]+'px';
  122. }
  123. }
  124.  
  125. function jamjar(ref) {
  126. if (ypos[ref]+dy[ref]<-50 || ypos[ref]+dy[ref]>shigh) rejig(ref, 'y');
  127. ypos[ref]+=dy[ref];
  128. if (xpos[ref]+dx[ref]<-50 || xpos[ref]+dx[ref]>swide) rejig(ref, 'x');
  129. xpos[ref]+=dx[ref];
  130. if (zpos[ref]+dz[ref]<0 || zpos[ref]+dz[ref]>20) dz[ref]=-dz[ref];
  131. zpos[ref]+=dz[ref];
  132. set_blob(ref);
  133. setTimeout("jamjar("+ref+")", speed);
  134. }
  135.  
  136. window.onresize=set_width;
  137. function set_width() {
  138. var sw_min=999999;
  139. var sh_min=999999;
  140. if (document.documentElement && document.documentElement.clientWidth) {
  141. if (document.documentElement.clientWidth>0) sw_min=document.documentElement.clientWidth;
  142. if (document.documentElement.clientHeight>0) sh_min=document.documentElement.clientHeight;
  143. }
  144. if (typeof(self.innerWidth)!="undefined" && self.innerWidth) {
  145. if (self.innerWidth>0 && self.innerWidth<sw_min) sw_min=self.innerWidth;
  146. if (self.innerHeight>0 && self.innerHeight<sh_min) sh_min=self.innerHeight;
  147. }
  148. if (document.body.clientWidth) {
  149. if (document.body.clientWidth>0 && document.body.clientWidth<sw_min) sw_min=document.body.clientWidth;
  150. if (document.body.clientHeight>0 && document.body.clientHeight<sh_min) sh_min=document.body.clientHeight;
  151. }
  152. if (sw_min==999999 || sh_min==999999) {
  153. sw_min=800;
  154. sh_min=600;
  155. }
  156. swide=sw_min;
  157. shigh=sh_min;
  158. }
  159. // ]]>
  160. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement