zoukankan      html  css  js  c++  java
  • 烟花

    <!DOCTYPE html>

    <html lang="en">

    <head>

    <meta charset="UTF-8">

    <title>放烟花</title>

    <style>

    div{

    position: absolute;

    }

    body{

    background: #000;

    overflow: hidden;

    }

    </style>

    </head>

    <body>

    </body>

    <script type="text/javascript">

    firework();

    function firework(){

    document.onclick=function(e){

    var oevent=e||event;

    //alert(oevent);

    var oreddiv=document.createElement("div");

    oreddiv.style.background="red";

    oreddiv.style.width="8px";

    oreddiv.style.height="8px";

    oreddiv.style.borderRadius="50%";

    oreddiv.style.left=oevent.clientX+"px";

    oreddiv.style.top=document.documentElement.clientHeight+"px";

    document.body.appendChild(oreddiv);

    var t=oevent.clientY;

    var l=oevent.clientX;

    var timer=setInterval(function(){

    oreddiv.style.top=oreddiv.offsetTop-20+"px";

    if(oreddiv.offsetTop<=t){

    clearInterval(timer);

    document.body.removeChild(oreddiv);

    var adiv=[];

    for(var i=0;i<50;i++){

    //每遍历一次,就生成一个div

    odiv=document.createElement("div");

    odiv.style.width="2px";

    odiv.style.height="2px";

    odiv.style.borderradius="50%";

    odiv.style.background="#"+fillzero();

    odiv.style.left=l+"px";

    odiv.style.top=t+"px";

    document.body.appendChild(odiv);

    adiv.push(odiv);

    odiv.speedX=Math.random()*40-20;

    odiv.speedY=Math.random()*40-20;

    }

    var newtimer=setInterval(function(){

    for(var i=0;i<adiv.length;i++){

    if(!adiv[i])continue;

    adiv[i].style.left=adiv[i].offsetLeft+adiv[i].speedX+"px";

    adiv[i].style.top=adiv[i].offsetTop+adiv[i].speedY+"px";

    adiv[i].speedY++;

    if(adiv[i].offsetLeft<0||adiv.offsetLeft>document.documentElement.clientWidth||adiv[i].offsetTop>document.documentElement.clientHeight){

    document.body.removeChild(adiv[i]);

    adiv[i] =null;

    }

    }

    },30)

    }

    },30);

    }

    function fillzero(){

    var strNum=Math.ceil(Math.random()*0xffffff).toString(16)

    if(strNum.length<6){

    strNum="0"+strNum;

    }

    return strNum;

    }

    }

    </script>

    </html>

  • 相关阅读:
    输出1到100内前五个可以被3整除的数 while for
    Java:运用while()与do....while与for()
    break & continue
    while循环
    for循环例子
    if语句条件
    上位机开发二----第一个程序hallo world
    c语言获取数组长度的三种方法
    halcon标定后畸变校正与测量
    海康相机SDK联合c++标定
  • 原文地址:https://www.cnblogs.com/wangxiaoshuai0401/p/5979458.html
Copyright © 2011-2022 走看看