以前看csdn上有人写的烟花,非常漂亮,一直想写。结果这么长的学习,算是可以一试了,发个0.5版本。仅供一笑
现在的问题是:计时器有2个,非常影响效率,在想办法改进中。
没有按照面对对象的写法。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
html,body { height:100%;}
body { background:#000; color:#FF0000; overflow:hidden;}
.divs { position:absolute; width:20px; height:20px;}
</style>
</head>
<body>
<script type="text/javascript">
var getRondom = function(small,big){
return small+(big-small)*Math.random();
}
var $ = function(id){ return document.getElementById(id);}
function circle(){
c=document.createElement('div');
c.innerHTML="*";
c.style.position ='absolute';
c.style.left = getRondom(200,window.screen.availWidth-200)+'px';
c.style.top = window.screen.availHeight-200 +'px';
document.body.appendChild(c);
h1 = getRondom(20,window.screen.availHeight-200);
h=window.screen.availHeight ;
t1 = setInterval(function(){h=h-10;c.style.top=h+"px"; if(h<=h1) {clearInterval(t1);start(c) }},10)
}
function show(s1,r1){
n=20;
divs = s1.getElementsByTagName('div');
for(var i=0; i<divs.length;i++){
divs[i].className='divs';
divs[i].style.left=r1*Math.cos(360/n*i)+'px';
divs[i].style.top=r1*Math.sin(360/n*i)+'px';
}
}
function start(s){
s.style.position='relative';
for(var i=0;i<20;i++){
s.appendChild(document.createElement('div'))['innerHTML']='*';
}
r=0;
show(s,r);
t = setInterval(function(){r=r+10;show(s,r); if(r>=150) {clearInterval(t);s.parentNode.removeChild(s); circle9 = new circle(); }},50)
}
circle1 = new circle();
</script>
</body>
</html>