<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>超炫网页烟花效果</title>
</head>
<style type="text/css">
.fire{display:block; overflow:hidden; font-size:12px; position:absolute};
body{overflow:hidden; background:#000}
html{overflow:hidden; background:#000}
</style>
<body>
</body>
<script type="text/javascript">
var Fire = function(r, color) {
this.radius = r || 12;
this.color = color;
this.xpos = 0;
this.ypos = 0;
this.zpos = 0;
this.vx = 0;
this.vy = 0;
this.vz = 0;
this.mass = 1;
this.x =0;
this.y=0;
this.p = document.createElement("span");
this.p.className = "fire";
this.p.innerHTML = "*";
this.p.style.fontSize = this.radius + "px";
this.p.style.color = "#" + this.color;
}
Fire.prototype = {
append: function(parent) {
parent.appendChild(this.p);
},
setSize: function(scale) {
this.p.style.fontSize = this.radius * scale + "px";
},
setPosition:function(x, y) {
this.p.style.left = x + "px";
this.p.style.top =  y + "px";
},
setVisible: function(b) {
this.p.style.display = b ? "block" : "none";
}
}
var fireworks = function() {
var fires = new Array();
var count = 150;
var fl = 250;
var vpx = 500;
var vpy = 300;
var gravity = .5;
var floor = 200;
var bounce = -.8;
var timer;
var wind = ((Math.floor(Math.random()*3) + 3)/10)*(Math.random()*2 - 1 > 0 ? 1 : -1)*.25;
var wpos = 0;
var wcount;
return {
init: function() {
wcount = 50 + Math.floor(Math.random() * 100);
for (var i=0; i<count; i++) {
var color = 0xFF0000;
color = (Math.random() * 0xFFFFFF).toString(16).toString().split(".")[0];
while(color.length < 6) {
color = "0" + color;
}
var fire = new Fire(12, color);
fires.push(fire);
fire.ypos = -100;
fire.vz = Math.random() * 6 - 3;
fire.vx = (Math.random()*2 - 1)*2 ;
fire.vy = Math.random()*-15 - 15;
fire.x = 500
fire.y = 600;
fire.append(document.body);
}
var that = this;
timer = setInterval(function() {
wpos++;
if (wpos >= wcount) {
wpos = 0;
wcount = 50 + Math.floor(Math.random() * 100);
wind = ((Math.floor(Math.random()*3) + 3)/10)*(Math.random()*2 - 1 > 0 ? 1 : -1)*.25;
}
for (var i=0;i<count; i++) {
that.move(fires[i]);
}
}, 30);
},
move: function(fire) {
fire.vy += gravity;
fire.x += fire.vx;
fire.y += fire.vy;
fire.vx += wind;
fire.setPosition(fire.x, fire.y);
if (fire.x < 0 || fire.x >1000 || fire.y  < 0 || fire.y  > 600) {
fire.vx = (Math.random()*2 - 1)*2;
fire.vy = Math.random()*-15 - 15;
fire.x = 500;
fire.y = 600;
fire.setPosition(fire.x, fire.y);
}
}
}
}
fireworks().init();
</script>
</html>

最新文章

  1. 关于el jstl
  2. List&lt;Map&lt;String,Object&gt;&gt;使用Java代码遍历
  3. Git: untrack a file in local repo only and keep it in the remote repo
  4. Google V8扩展利器发布:v8-native-binding-generator
  5. error: qrc_qml.obj: requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC解决办法
  6. IOS xib生成界面和代码生成界面两种方式混合
  7. 【HTTP】HTTP access control (CORS)
  8. JSP导出Excel文件
  9. 基于 Android 的 3D 视频样本代码
  10. Mongodb相关 (Shell命令 / mongoose)
  11. px妙转rem
  12. Hadoop(五)搭建Hadoop客户端与Java访问HDFS集群
  13. 通过Webstorm上传代码到Github、更新代码后同步到github及克隆github代码到本地的方法
  14. CSS之2D转换模块
  15. Lyk Love painting/convex hull/mumsic
  16. 算法课笔记系列(七)—— 平摊分析Amortized Analysis
  17. Linux命令学习之路——档案拷贝:cp
  18. Vue.js入门系列(一)
  19. wpgcms---详情页面数据怎么渲染
  20. Android wifi无线调试App新玩法ADB WIFI

热门文章

  1. OpenCV_CS.测试
  2. 在HTML5 中使用 kindeditor 的方法
  3. elasticsearch备份脚本
  4. 洛谷 题解 CF711A 【Bus to Udayland】
  5. Coloring Edges 【拓扑判环】
  6. jquery(第一章)认识jquery
  7. java基础知识入门
  8. 对称加密、非对称加密、数字签名、数字证书、SSL是什么
  9. 网络流Dinic--模板
  10. Python中的with语句(上下文管理协议)