js烟花特效

前端之家收集整理的这篇文章主要介绍了js烟花特效前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <Meta http-equiv="Content-Type" content="text/html; charset=gbk" />
  5. <title>JavaScript烟花丨Showcoo|秀客丨showcoo.net</title>
  6. <script type="text/javascript">
  7. var showcoo = function(){
  8. this.size = 40;
  9. this.speed = 0.1;
  10. this.rise();
  11. }
  12. showcoo.prototype = {
  13. color:function(){
  14. var c = ['0','3','6','9','c','f'];
  15. var t = [c[Math.floor(Math.random()*100)%6],'0','f'];
  16. t.sort(function(){return Math.random()>0.5?-1:1;});
  17. return '#'+t.join('');
  18. },aheight:function(){
  19. var h = document.documentElement.clientHeight;
  20. return Math.abs(Math.floor(Math.random()*h-200))+201;
  21. },firecracker:function(){
  22. var b = document.createElement('div');
  23. var w = document.body.clientWidth;
  24. b.style.color = this.color();
  25. b.style.position = 'absolute';
  26. b.style.bottom = 0;
  27. b.style.left = Math.floor(Math.random()*w)+1+'px';
  28. document.body.appendChild(b);
  29. return b;
  30. },rise:function(){
  31. var o = this.firecracker();
  32. var n = this.aheight();
  33. var speed = this.speed;
  34. var e = this.expl;
  35. var s = this.size;
  36. var k = n;
  37. var m = function(){
  38. o.style.bottom = parseFloat(o.style.bottom)+k*speed+'px';
  39. k-=k*speed;
  40. if(k<2){
  41. clearInterval(clear);
  42. e(o,n,s,speed);
  43. }
  44. }
  45. o.innerHTML = '*';
  46. if(parseInt(o.style.bottom)<n){
  47. var clear = setInterval(m,20);
  48. }
  49. },expl:function(o,speed){
  50. var R = n/3;
  51. var Ri = n/6;
  52. var r = 0;
  53. var ri = 0;
  54. for(var i=0;i<s;i++){
  55. var span = document.createElement('span');
  56. var p = document.createElement('p');
  57. span.style.position = 'absolute';
  58. span.style.left = 0;
  59. span.style.top = 0;
  60. span.innerHTML = '*';
  61. p.style.position = 'absolute';
  62. p.style.left = 0;
  63. p.style.top = 0;
  64. p.innerHTML = '+';
  65. o.appendChild(span);
  66. o.appendChild(p);
  67. }
  68. function spr(){
  69. r += R*speed;
  70. ri+= Ri*speed/2;
  71. sp = o.getElementsByTagName('span');
  72. p = o.getElementsByTagName('p');
  73. for(var i=0; i<sp.length;i++){
  74. sp[i].style.left=r*Math.cos(360/s*i)+'px';
  75. sp[i].style.top=r*Math.sin(360/s*i)+'px';
  76. p[i].style.left=ri*Math.cos(360/s*i)+'px';
  77. p[i].style.top=ri*Math.sin(360/s*i)+'px';
  78. }
  79. R-=R*speed;
  80. if(R<2){
  81. clearInterval(clearI);
  82. o.parentNode.removeChild(o);
  83. }
  84. }
  85. var clearI = setInterval(spr,20);
  86. }
  87. }
  88. window.onload = function(){
  89. function happyNewYear(){
  90. new showcoo();
  91. }
  92. setInterval(happyNewYear,400);
  93. }
  94. </script>
  95. <style type="text/css">
  96. </style>
  97. </head>
  98. <body style="background:#000;font:12px Arial">
  99. </body>
  100. </html>
  101.  
  102. <font color="white"><p align="center">本特效由 <a href="http://www.showcoo.net">Showcoo|秀客</a>提供</p></font>

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

猜你在找的HTML相关文章