国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

js由下向上不斷上升冒氣泡效果實例

2024-05-06 16:19:39
字體:
供稿:網(wǎng)友

這篇文章主要介紹了js由下向上不斷上升冒氣泡效果,實例分析了javascript操作鼠標事件、圖片及樣式的相關(guān)技巧,需要的朋友可以參考下

本文實例講述了js由下向上不斷上升冒氣泡效果的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

 

 
  1. <html> 
  2. <head> 
  3. <title>JS實現(xiàn)氣泡從水中急速上升效果</title> 
  4. <style type="text/css"
  5. body { 
  6. cursor:crosshair;margin:0; padding:0; 
  7. position:absolute; overflow:hidden; 
  8. background:#FFF; left:0; top:0; 
  9. width:100%; height:100%; 
  10. </style> 
  11. <script type="text/javascript"
  12. var object = new Array(); 
  13. nbfm = 60; 
  14. var xm = 0; 
  15. var ym = 9999; 
  16. var nx = 0; 
  17. var ny = 0; 
  18. function movbulb(){ 
  19. with (this) { 
  20. if(ec < 20){ 
  21. if(Math.abs(x0 - xm) < 100 && Math.abs(y0 - ym) < 100){ 
  22. xx = (xm - x0) / 8; 
  23. yy = (ym - y0) / 8; 
  24. ec++; 
  25. xx *= 0.99; 
  26. yy *= 0.99; 
  27. x0 = Math.round(x0 + Math.cos(y0 / 15) * p) + xx; 
  28. y0+= yy - v; 
  29. if(y0 < -h * 2 || x0 < -w * 2 || x0 > nx + w * 2){ 
  30. y0 = ny + N + h * 2; 
  31. x0 = nx/2-100 + Math.random() * 100; 
  32. ec = 0; 
  33. obj.style.top = y0 - h; 
  34. obj.style.left = x0 - w; 
  35. function CObj(N,img,w,h){ 
  36. this.obj = document.createElement("img"); 
  37. this.obj.src = img.src; 
  38. this.obj.style.position = "absolute"
  39. this.obj.style.left = -1000; 
  40. document.body.appendChild(this.obj); 
  41. this.N = N; 
  42. this.x0 = 0; 
  43. this.y0 = -1000; 
  44. this.v = 1 + Math.round((80 / h) * Math.random()); 
  45. this.p = 1 + Math.round((w / 8) * Math.random()); 
  46. this.xx = 0; 
  47. this.yy = 0; 
  48. this.ec = 0; 
  49. this.w = w; 
  50. this.h = h; 
  51. this.movbulb = movbulb; 
  52. function resize(){ 
  53. nx = document.body.offsetWidth; 
  54. ny = document.body.offsetHeight; 
  55. onresize = resize; 
  56. document.onmousemove = function(e){ 
  57. if (window.event) e = window.event; 
  58. xm = document.body.scrollLeft+(e.x || e.clientX); 
  59. ym = document.body.scrollTop+(e.y || e.clientY); 
  60. function run(){ 
  61. for(i in object)object[i].movbulb(); 
  62. setTimeout(run, 16); 
  63. onload = function() { 
  64. PIC = document.getElementById("bubbles").getElementsByTagName("img"); 
  65. resize(); 
  66. for(nbf=0;nbf<nbfm;nbf++){ 
  67. sf = PIC[nbf%PIC.length]; 
  68. object[nbf] = new CObj(nbf,sf,sf.width/2,sf.height/2); 
  69. run(); 
  70. </script> 
  71. </head> 
  72. <body> 
  73. <div id="bubbles" style="visibility:hidden"
  74. <img src="http://bbs.blueidea.com/static/image/smiley/blueidea/smile.gif"
  75. <img src="http://bbs.blueidea.com/static/image/smiley/blueidea/biggrin.gif"
  76. <img src="http://bbs.blueidea.com/static/image/smiley/blueidea/eek.gif"
  77. <img src="http://bbs.blueidea.com/static/image/smiley/blueidea/rolleyes.gif"
  78. </div> 
  79. </body> 
  80. </html> 

希望本文所述對大家的javascript程序設計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 上蔡县| 武鸣县| 东方市| 应用必备| 吴桥县| 玛纳斯县| 华池县| 巴塘县| 泰来县| 盐边县| 社旗县| 台山市| 巴林左旗| 铜川市| 鄂托克前旗| 苍溪县| 若羌县| 积石山| 日土县| 合肥市| 龙海市| 铁岭县| 临漳县| 全南县| 阿荣旗| 小金县| 彰武县| 罗田县| 淳化县| 东丽区| 修武县| 镇巴县| 鄂托克旗| 灌南县| 河南省| 常山县| 孟州市| 商洛市| 永平县| 阿荣旗| 常熟市|