• 烟花


    <!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>
  • 相关阅读:
    获取屏幕分辨率
    String-去除-指定-字符-操作
    Log4j配置详述
    Java-String-数据乱码
    javascript高级课程-3
    javascript高级课程-2
    javascript高级课程-1
    设计一个算法双链表删除重复
    设计一个算法将一个顺序表逆置
    w3c标准
  • 原文地址:https://www.cnblogs.com/huangping199541/p/11456512.html
Copyright © 2020-2023  润新知