zoukankan      html  css  js  c++  java
  • 烟花

    <!DOCTYPE html>
    <html>
    
        <head>
            <meta charset="UTF-8">
            <title></title>
            <style type="text/css">
                #box {
                     1200px;
                    height: 700px;
                    background-color: #000000;
                    border: 3px solid purple;
                    margin: 200px auto;
                    position: relative;
                }
                
                .fire {
                     5px;
                    height: 5px;
                    border-radius: 50%;
                    position: absolute;
                    left: 0;
                    bottom: 0;
                }
                
                .smallfire {
                     5px;
                    height: 5px;
                    border-radius: 50%;
                    position: absolute;
                }
            </style>
        </head>
    
        <body>
            <div id="box">
    
            </div>
        </body>
        <script src="move.js">
        </script>
        <script type="text/javascript">
            function Fire(obj) {
                this.x = obj.x;
                this.y = obj.y;
                this.obox = parent.obox;
                this.init();
            }
            Fire.prototype.init = function() {
                this.ele = document.createElement("div");
                this.ele.className = "fire";
                this.ele.style.backgroundColor = randomcolor();
                this.ele.style.left = this.x + "px";
    
                this.obox.appendChild(this.ele);
                this.animit();
            }
            Fire.prototype.animit = function() {
                move(this.ele, {
                    top: this.y
                }, function() {
                    this.ele.remove();
                    this.ceratesmall();
                }.bind(this))
    
            }
            Fire.prototype.ceratesmall = function() {
                var num = random(15, 25)
                for(i = 0; i < num; i++) {
                    let div = document.createElement("div");
                    div.className = "smallfire";
                    div.style.left = this.x + "px";
                    div.style.top = this.y + "px";
                    div.style.backgroundColor = randomcolor();
                    this.obox.appendChild(div);
                    var l = random(0, this.obox.offsetWidth)
                    var t = random(0, this.obox.offsetHeight)
                    move(div, {
                        left: l,
                        top: t
                    }, function() {
                        div.remove()
                    })
    
                }
    
            }
    
            function randomcolor() {
                return "rgb(" + random(0, 255) + "," + random(0, 255) + "," + random(0, 255) + ")";
            }
    
            function random(a, b) {
                return Math.round(Math.random() * (a - b) + b);
            }
    
            function getStyle(ele, attr) {
                if(ele.currentStyle) {
                    return ele.currentStyle[attr];
                } else {
                    return getComputedStyle(ele, false)[attr];
                }
            }
    
            var obox = document.querySelector("#box");
            obox.onclick = function(eve) {
                
                var e = eve || window.event;
    //            console.log(e.offsetX)
                new Fire({
                    x: e.offsetX,
                    y: e.offsetY,
                    
                    parent: obox,
                })
    
            }
        </script>
    
    </html>
  • 相关阅读:
    查找数据库表中重复的 Image 类型值
    C#中的引用传递和值传递。
    用JS解决Asp.net Mvc返回JsonResult中DateTime类型数据格式的问题
    根据业务自己设计的.NET工厂模式架构
    封装EF code first用存储过程的分页方法
    2013款MacBook Air装Windows7单系统
    js判断是否在微信浏览器中打开
    EF Code First连接现有数据库
    JS中for循序中延迟加载实现动态效果
    DIV+CSS左右两列自适应高度的方法
  • 原文地址:https://www.cnblogs.com/huangping199541/p/11456512.html
Copyright © 2011-2022 走看看