• <noscript id="ggggg"><dd id="ggggg"></dd></noscript>
    <small id="ggggg"></small> <sup id="ggggg"></sup>
    <noscript id="ggggg"><dd id="ggggg"></dd></noscript>
    <tfoot id="ggggg"></tfoot>
  • <nav id="ggggg"><cite id="ggggg"></cite></nav>
    <nav id="ggggg"></nav>
    成人黃色A片免费看三更小说,精品人妻av区波多野结衣,亚洲第一极品精品无码,欧美综合区自拍亚洲综合,久久99青青精品免费观看,中文字幕在线中字日韩 ,亚洲国产精品18久久久久久,黄色在线免费观看

    教你用面向?qū)ο缶幊虒?xiě)一個(gè)煙花爆炸的

    2020-3-23    前端達(dá)人

    點(diǎn)擊查看原圖



    想要學(xué)會(huì)這個(gè)漂亮的煙花嗎?快來(lái)跟著學(xué)習(xí)吧~

    結(jié)構(gòu)

    <div class="container"></div>

    我們只需要一個(gè)盒子表示煙花爆炸范圍就可以了

    樣式

    fire是煙花 注意添加絕對(duì)定位

     <style>
        .container{
            margin: 0 auto;
            height: 500px;
            width: 1200px;
            background: black;
            position: relative;
            overflow: hidden;
        }
        .fire{
            width: 10px;
            background: white;
            height: 10px;
            /* border-radius: 50%; */
            position: absolute;
            bottom: 0;
        }
        </style>
    



    行為

    編寫(xiě)構(gòu)造函數(shù)Firework

    需要用到一個(gè)鼠標(biāo)點(diǎn)擊的位置,一個(gè)div選擇器,一個(gè)爆炸樣式

     function Firework(x,y,selector,type){
            //此處獲取對(duì)象的方式為單例的思想,避免重復(fù)獲取相同的元素
            if(Firework.box && selector === Firework.box.selector){
                this.box =  Firework.box.ele;
            }else{
                Firework.box = {
                    ele:document.querySelector(selector),
                    selector:selector
                }
                this.box = Firework.box.ele;
            }
            this.type = type;
            this.init(x,y)
        }
    



    封裝一個(gè)運(yùn)動(dòng)的方法
    function animation(ele,attroptions,callback){
        for(var attr in attroptions){
            attroptions[attr] ={
                target:attroptions[attr],
                inow:parseInt(getComputedStyle(ele)[attr])
            } 
        }
        clearInterval(ele.timer);
        ele.timer = setInterval(function(){
            for(var attr in attroptions ){
                var item = attroptions[attr]
                var target = item.target;
                var inow = item.inow;
                var speed = (target - inow)/10;
                speed = speed>0?Math.ceil(speed):Math.floor(speed);
                if(Math.abs(target - inow) <= Math.abs(speed)){
                    ele.style[attr] = target+"px";
                    delete attroptions[attr];
                    for(var num  in attroptions){
                        return false;
                    }
                    clearTimeout(ele.timer);
                    if(typeof callback === "function")callback();
                }else{
                    attroptions[attr].inow += speed;
                    ele.style[attr]  = attroptions[attr].inow+"px";
                }
            }
        },30)
    }
    



    編寫(xiě)原型方法
    Firework.prototype = {
            constructor:Firework,
            //初始化
            init:function(x,y){
                //創(chuàng)建一個(gè)煙花
                this.ele = this.createFirework();
                //xy為鼠標(biāo)落點(diǎn)
                this.x = x ;
                this.y = y;
                //maxXy為最大運(yùn)動(dòng)范圍
                this.maxX = this.box.offsetWidth - this.ele.offsetWidth;
                this.maxY = this.box.offsetHeight - this.ele.offsetHeight;
                //初始化結(jié)束后  煙花隨機(jī)顏色
                this.randomColor(this.ele);
                //煙花升空
                this.fireworkUp(this.ele);
            },
            //創(chuàng)造煙花
            createFirework:function(){
                var ele = document.createElement("div");
                ele.className = "fire";
                this.box.appendChild(ele);
                return ele;
            },
            //煙花升空
            fireworkUp:function(ele){
                ele.style.left = this.x + "px";
                //此處用到剛剛封裝的運(yùn)動(dòng)方法
                animation(ele,{top:this.y},function(){
                    ele.remove();
                    this.fireworkBlast()
                }.bind(this));
            },
            //煙花爆炸
            fireworkBlast:function(){
                for(var i = 0 ; i < 20; i++){
                    var ele = document.createElement("div");
                    ele.className = "fire";
                    ele.style.left = this.x + "px";
                    ele.style.top = this.y + "px";
                    this.box.appendChild(ele);
                    ele.style.borderRadius = "50%";
                    this.randomColor(ele);
                    //判定一下輸入的爆炸方式是原型煙花 還是散落煙花 由此更改獲取的煙花位置
                    animation(ele,this.type === "circle"?this.circleBlast(i,20): this.randomPosition(),function(cale){
                        cale.remove();
                    }.bind(this,ele))
                }
            },
            //圓形爆炸位置
            circleBlast:function(i,total){
                var r = 200;
                var reg = 360 / total *i;
                var deg = Math.PI / 180 *reg;
                return {
                    left:r * Math.cos(deg) + this.x ,
                    top:r * Math.sin(deg) + this.y 
                }
            },
            //隨機(jī)顏色
            randomPosition:function(){
                return {
                    left : Math.random()*this.maxX,
                    top : Math.random()*this.maxY
                }
            },
            randomColor:function(ele){
                var color =  "#" + parseInt(parseInt("ffffff",16)*Math.random()).toString(16).padStart(6,0);
                return ele.style.backgroundColor = color;
            }
        }
    



    綁定事件
    document.querySelector(".container").addEventListener("click",function(evt){
        var e = evt||event;
        new Firework(e.offsetX,e.offsetY,".container","circle")
        new Firework(e.offsetX,e.offsetY,".container")
    })
    
    
    

    全部代碼

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
        .container{
            margin: 0 auto;
            height: 500px;
            width: 1200px;
            background: black;
            position: relative;
            overflow: hidden;
        }
        .fire{
            width: 10px;
            background: white;
            height: 10px;
            /* border-radius: 50%; */
            position: absolute;
            bottom: 0;
        }
        </style>
    </head>
    <body>
        <div class="container"></div>
        <script src="./utils.js"></script>
        <script>
    
        function animation(ele,attroptions,callback){
            for(var attr in attroptions){
                attroptions[attr] ={
                    target:attroptions[attr],
                    inow:parseInt(getComputedStyle(ele)[attr])
                } 
            }
            clearInterval(ele.timer);
            ele.timer = setInterval(function(){
                for(var attr in attroptions ){
                    var item = attroptions[attr]
                    var target = item.target;
                    var inow = item.inow;
                    var speed = (target - inow)/10;
                    speed = speed>0?Math.ceil(speed):Math.floor(speed);
                    if(Math.abs(target - inow) <= Math.abs(speed)){
                        ele.style[attr] = target+"px";
                        delete attroptions[attr];
                        for(var num  in attroptions){
                            return false;
                        }
                        clearTimeout(ele.timer);
                        if(typeof callback === "function")callback();
                    }else{
                        attroptions[attr].inow += speed;
                        ele.style[attr]  = attroptions[attr].inow+"px";
                    }
                }
            },30)
        }  
    
            function Firework(x,y,selector,type){
                if(Firework.box && selector === Firework.box.selector){
                    this.box =  Firework.box.ele;
                }else{
                    Firework.box = {
                        ele:document.querySelector(selector),
                        selector:selector
                    }
                    this.box = Firework.box.ele;
                }
                this.type = type;
                this.init(x,y)
            }
    
            Firework.prototype = {
                constructor:Firework,
                //初始化
                init:function(x,y){
                    this.ele = this.createFirework();
                    this.x = x ;
                    this.y = y;
                    this.maxX = this.box.offsetWidth - this.ele.offsetWidth;
                    this.maxY = this.box.offsetHeight - this.ele.offsetHeight;
                    this.randomColor(this.ele);
                    this.fireworkUp(this.ele);
                },
                //創(chuàng)造煙花
                createFirework:function(){
                    var ele = document.createElement("div");
                    ele.className = "fire";
                    this.box.appendChild(ele);
                    return ele;
                },
                fireworkUp:function(ele){
                    ele.style.left = this.x + "px";
                    animation(ele,{top:this.y},function(){
                        ele.remove();
                        this.fireworkBlast()
                    }.bind(this));
                },
                //煙花爆炸
                fireworkBlast:function(){
                    for(var i = 0 ; i < 20; i++){
                        var ele = document.createElement("div");
                        ele.className = "fire";
                        ele.style.left = this.x + "px";
                        ele.style.top = this.y + "px";
                        this.box.appendChild(ele);
                        ele.style.borderRadius = "50%";
                        this.randomColor(ele);
                        animation(ele,this.type === "circle"?this.circleBlast(i,20): this.randomPosition(),function(cale){
                            cale.remove();
                        }.bind(this,ele))
                    }
                },
                circleBlast:function(i,total){
                    var r = 200;
                    var reg = 360 / total *i;
                    var deg = Math.PI / 180 *reg;
                    return {
                        left:r * Math.cos(deg) + this.x ,
                        top:r * Math.sin(deg) + this.y 
                    }
                },
                randomPosition:function(){
                    return {
                        left : Math.random()*this.maxX,
                        top : Math.random()*this.maxY
                    }
                },
                randomColor:function(ele){
                    var color =  "#" + parseInt(parseInt("ffffff",16)*Math.random()).toString(16).padStart(6,0);
                    return ele.style.backgroundColor = color;
                }
            }
    
            document.querySelector(".container").addEventListener("click",function(evt){
                var e = evt||event;
                new Firework(e.offsetX,e.offsetY,".container","circle")
                new Firework(e.offsetX,e.offsetY,".container")
            })
        </script>
    </body>
    </html>
    

    ————————————————
    版權(quán)聲明:本文為CSDN博主「SpongeBooob」的原創(chuàng)文章,遵循 CC 4.0 BY-SA 版權(quán)協(xié)議,轉(zhuǎn)載請(qǐng)附上原文出處鏈接及本聲明。
    原文鏈接:https://blog.csdn.net/qq_41383900/article/details/105026768
    
    


    日歷

    鏈接

    個(gè)人資料

    存檔

    主站蜘蛛池模板: 欧美xxxxx精品| 美女内射中出草草视频| 日本韩国国产精品自拍| 国产噜噜在线视频观看| 伊人一伊人色综合网| www.五月丁香| 狠狠色狠狠色综合网老熟女| 在线a人片免费观看| 国产在线视频你懂的| 国产A片| 岑巩县| 欧美高清日韩在线视频观看| 丝袜美腿精品国产一区| 深夜av免费在线观看| 国产成人精品午夜2022| 亚洲AV无码日韩一区二区乱| 亚洲情XO亚洲色XO无码| 色综合久久久久无码专区| 日韩区欧美国产区在线观看 | 国产精品小蝌蚪福利| 国产精品久久久久精| 国产高清自产拍AV在线| 激情一区| 黄色一级片在线观看| 国产成人精品免费av| 看污网址| 国产福利精品导航网址| 欧美又粗又长又爽做受| 可以免费看的天堂av| 亚洲AV片一区二区三区| 精品国产乱码久久久久久郑州公司| 色屁屁WWW影院免费观看入口| 久久一本人碰碰人碰| 国产日韩久久久久69影院| 久久久久久久波多野结衣高潮| 欧美白妞大战非洲大炮| 久久天天躁狠狠躁夜夜躁2o2o| 精品 无码 国产观看| 亚洲精品乱码中文字幕| 欧产日产国产精品精品| 屏南县|