Advertisement
thuechen

Bubbles effect

Jun 4th, 2015
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. <!-- this script got from www.htmlbestcodes.com-Coded by: Krishna Eydat -->
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6. <script language="JavaScript1.2">
  7.  
  8. var no = 15; // image number or falling rate
  9. var speed = 2; // the lower the number the faster the image moves
  10. var snow = new Array();
  11. snow[0] = "http://www.htmlbestcodes.com/images/bubble.gif"
  12. snow[1] = "http://www.htmlbestcodes.com/images/bubble.gif"
  13. snow[2] = "http://www.htmlbestcodes.com/images/bubble.gif"
  14.  
  15. var ns4up = (document.layers) ? 1 : 0; // browser sniffer
  16. var ie4up = (document.all) ? 1 : 0;
  17. var ns6up = (document.getElementById&&!document.all) ? 1 : 0;
  18. var dx, xp, yp; // coordinate and position variables
  19. var am, stx, sty; // amplitude and step variables
  20. var i, doc_width = 800, doc_height = 1800;
  21.  
  22. if (ns4up||ns6up) {
  23. doc_width = self.innerWidth;
  24. doc_height = self.innerHeight;
  25. } else if (ie4up) {
  26. doc_width = document.body.clientWidth;
  27. doc_height = document.body.clientHeight;
  28. }
  29.  
  30. dx = new Array();
  31. xp = new Array();
  32. yp = new Array();
  33. am = new Array();
  34. stx = new Array();
  35. sty = new Array();
  36. j = 0;
  37.  
  38. for (i = 0; i < no; ++ i) {
  39. dx[i] = 0; // set coordinate variables
  40. xp[i] = Math.random()*(doc_width-50); // set position variables
  41. yp[i] = Math.random()*doc_height;
  42. am[i] = Math.random()*20; // set amplitude variables
  43. stx[i] = 0.02 + Math.random()/10; // set step variables
  44. sty[i] = 0.7 + Math.random(); // set step variables
  45. if (ns4up) { // set layers
  46. if (i == 0) {
  47. document.write("<layer name=\"dot"+ i +"\" left=\"15\" top=\"15\" visibility=\"show\"><img src=\""+ snow[j] + "\" border=\"0\"></layer>");
  48. } else {
  49. document.write("<layer name=\"dot"+ i +"\" left=\"15\" top=\"15\" visibility=\"show\"><img src=\""+ snow[j] + "\" border=\"0\"></layer>");
  50. } } else if (ie4up||ns6up) { if (i == 0)
  51. {
  52. document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"VISIBILITY: visible; TOP: 15px; LEFT: 15px; width:1;\"><img src=\"" + snow[j] + "\" border=\"0\"></div>");
  53. } else {
  54. document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"VISIBILITY: visible; TOP: 15px; LEFT: 15px; width:1;\"><img src=\"" + snow[j] + "\" border=\"0\"></div>");
  55. }
  56. }
  57. if (j == (snow.length-1)) { j = 0; } else { j += 1; }
  58. }
  59.  
  60. function snowNS() { // Netscape main animation function
  61. for (i = 0; i < no; ++ i) { // iterate for every dot
  62. yp[i] -= sty[i]; if (yp[i] < -50) {
  63. xp[i] = Math.random()*(doc_width-am[i]-30);
  64. yp[i] = doc_height;
  65. stx[i] = 0.02 + Math.random()/10;
  66. sty[i] = 0.7 + Math.random();
  67. doc_width = self.innerWidth;
  68. doc_height = self.innerHeight; }
  69. dx[i] += stx[i];
  70. document.layers["dot"+i].top = yp[i]+pageYOffset;
  71. document.layers["dot"+i].left = xp[i] +
  72. am[i]*Math.sin(dx[i]);
  73. }
  74. setTimeout("snowNS()", speed);
  75. }
  76.  
  77. function snowIE_NS6() { // IE main animation function
  78. for (i = 0; i < no; ++ i) { // iterate for every dot
  79. yp[i] -= sty[i];
  80. if (yp[i] < -50) {
  81. xp[i] = Math.random()*(doc_width-am[i]-30);
  82. yp[i] = doc_height;
  83. stx[i] = 0.02 + Math.random()/10;
  84. sty[i] = 0.7 + Math.random();
  85. doc_width = ns6up?window.innerWidth-5:document.body.clientWidth;
  86. doc_height = ns6up?window.innerHeight-5:document.body.clientHeight;
  87. }
  88. dx[i] += stx[i];
  89. if (ie4up){
  90. document.all["dot"+i].style.pixelTop = yp[i]+document.body.scrollTop;
  91. document.all["dot"+i].style.pixelLeft = xp[i] + am[i]*Math.sin(dx[i]);
  92. }
  93. else if (ns6up){
  94. document.getElementById("dot"+i).style.top=yp[i]+pageYOffset;
  95. document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i]);
  96. }
  97. }
  98. setTimeout("snowIE_NS6()", speed);
  99. }
  100.  
  101. if (ns4up) {
  102. snowNS();
  103. } else if (ie4up||ns6up) {
  104. snowIE_NS6();
  105. }
  106. // End -->
  107. </script>
  108.  
  109. <div style="clear:both"></div><div><a target="_blank" href="http://www.htmlbestcodes.com/"><span style="font-size: 8pt; text-decoration: none">HTML Best Codes</span></a></div>
  110. </body>
  111. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement