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>
  • 相关阅读:
    [loj3364]植物比较
    [loj3366]嘉年华奖券
    [atARC105F]Lights Out on Connected Graph
    [atARC105D]Let's Play Nim
    [atARC058F]Lroha Loves Strings
    [loj3347]有趣的旅途
    [atAGC001F]Wide Swap
    [cf1392I]Kevin and Grid
    [loj3340]命运
    [loj3046]语言
  • 原文地址:https://www.cnblogs.com/huangping199541/p/11456512.html
Copyright © 2011-2022 走看看