戦闘へのWebフロントエンドの取得:CSS、JSは、ロマンチックな流星群のアニメーションを実現

1、図の効果。

戦闘へのWebフロントエンドの取得:CSS、JSは、ロマンチックな流星群のアニメーションを実現

図2に示すように、ソース

HTML

< body > 
    < div  class = “container” > 
        < div  id = “mask” > </ div > 
        < div  id = “sky” > </ div > 
        < div  id = “moon” > </ div > 
        < div  id = “stars” > </ div > 
        < div  class = “cloud cloud-1” ></ div > 
        <div  class = “cloud cloud-2” > </ div > 
        < div  class = “cloud cloud-3” > </ div > 
    </ div > 
</ body >
web前端开发学习Q-q-u-n: 731771211,分享学习的方法和需要注意的小细节,不停更新最新的教程和学习方法(详细的前端项目实战教学视频)

CSS

/*  -  -  -  -  -  - 重启 -  -  -  -  -  -  */

 * {
     保证金:0 ;
     填充:0 ;
 }

 html,
  body {
      width:100% ;
     最小宽度:1000px ;
     身高:100% ;
     最小高度:400px ;
     溢出:隐藏;
 }

 / * ------------画布------------ * / 
 .container {
      position:relative;
     身高:100% ;
 }
 / *遮罩层* /

 #mask {
      position:absolute;
     宽度:100% ;
     身高:100% ;
     background:rgba(0,0,0,.8);
     z-index:900 ;
 }
 / *天空背景* /

 #sky {
      width:100% ;
     身高:100% ;
     background:线性渐变(rgba(0,150,255,1),rgba(0,150,255,.8),rgba(0,150,255,.5));
 }
 / *月亮* /

 #moon {
      position:absolute;
     上:50px ;
     右:200px ;
     宽度:120px ;
     身高:120px ;
     背景:rgba(251,255,25,0.938);
     border-radius:50% ;
     box-shadow:0  0  20px  rgba(251,255,25,0.5);
     z-index:9999 ;
 }
 / *闪烁星星* /

 .blink {
      position:absolute;
     background:rgb(255,255,255);
     border-radius:50% ;
     box-shadow:0  0  5px  rgb(255,255,255);
     不透明度:0 ;
     z-index:10000 ;
 }
 / *流星* /

 .star {
      position:absolute;
     不透明度:0 ;
     z-index:10000 ;
 }

 .star :: after {
      content:“” ;
     显示:块;
     边界:坚固;
     border-width:2px  0  2px  80px ;
     / *流星随长度逐渐缩小* / 
     border-color:透明透明透明rgba(255,255,255,1);
     border-radius:2px  0  0  2px ;
     transform:rotate(-45deg);
     transform-origin:0  0  0 ;
     盒子阴影:0  0  20px  rgba(255,255,255,.3);
 }
 / *云* /

 .cloud {
      position:absolute;
     宽度:100% ;
     身高:100px ;
 }

 .cloud-1 {
      bottom: - 100px ;
     z-index:1000 ;
     不透明度:1 ;
     变换:规模(1.5);
     -webkit-transform:scale(1.5);
     -moz-transform:scale(1.5);
     -ms-transform:scale(1.5);
     -o-transform:scale(1.5);
 }

 .cloud-2 {
      left: - 100px ;
     底部: - 50px ;
     z-index:999 ;
     不透明度:。5 ;
     变换:旋转(7deg);
     -webkit-transform:rotate(7deg);
     -moz-transform:rotate(7deg);
     -ms-transform:rotate(7deg);
     -o-transform:rotate(7deg);
 }

 .cloud-3 {
      left:120px ;
     底部: - 50px ;
     z-index:999 ;
     不透明度:。1 ;
     transform:rotate(-10deg);
     -webkit-transform:rotate(-10deg);
     -moz-transform:rotate(-10deg);
     -ms-transform:rotate(-10deg);
     -o-transform:rotate(-10deg);
 }

 .circle {
      position:absolute;
     border-radius:50% ;
     背景:#fff ;
 }

 .circle-1 {
      width:100px ;
     身高:100px ;
     上: - 50px ;
     左:10px ;
 }

 .circle-2 {
      width:150px ;
     身高:150px ;
     上: - 50px ;
     左:30px ;
 }

 .circle-3 {
      width:300px ;
     身高:300px ;
     上: - 100px ;
     左:80px ;
 }

 .circle-4 {
      width:200px ;
     身高:200px ;
     上: - 60px ;
     左:300px ;
 }

 .circle-5 {
      width:80px ;
     身高:80px ;
     上: - 30px ;
     左:450px ;
 }

 .circle-6 {
      width:200px ;
     身高:200px ;
     上: - 50px ;
     左:500px ;
 }

 .circle-7 {
      width:100px ;
     身高:100px ;
     上: - 10px ;
     左:650px ;
 }

 .circle-8 {
      width:50px ;
     身高:50px ;
     上:30px ;
     左:730px ;
 }

 .circle-9 {
      width:100px ;
     身高:100px ;
     上:30px ;
     左:750px ;
 }

 .circle-10 {
      width:150px ;
     身高:150px ;
     上:10px ;
     左:800px ;
 }

 .circle-11 {
      width:150px ;
     身高:150px ;
     上: - 30px ;
     左:850px ;
 }

 .circle-12 {
      width:250px ;
     身高:250px ;
     上: - 50px ;
     左:900px ;
 }

 .circle-13 {
      width:200px ;
     身高:200px ;
     上: - 40px ;
     左:1000px ;
 }

 .circle-14 {
      width:300px ;
     身高:300px ;
     上: - 70px ;
     左:1100px ;
 }

JS

//流星动画 
setInterval(function() {
     const obj = addChild(“#sky”,“div”,2,“star”);

    for(let i = 0 ; i <obj.children.length; i ++){
         const top = -50 + Math .random()* 200 + “px”,
            left = 200 + Math .random()* 1200 + “px”,
            scale = 0.3 + Math .random()* 0.5 ;
        const timer = 1000 + Math .random()* 1000 ;

        obj.children [i] .style.top = top;
        obj.children [i] .style.left = left;
        obj.children [i] .style.transform = `scale($ {scale})` ;

        requestAnimation({
            ele:obj.children [i],
             attr:[ “top”,“left”,“opacity” ],
             值:[ 150,-150,.8 ],
             time:timer,
             flag:false,
             fn:function() {
                requestAnimation({
                    ELE:obj.children [I],
                     ATTR:“顶”,“左”,“不透明” ],
                     值:[ 150,-150,0 ],
                     时间:定时器,
                     标志:假,
                     FN:() => {
                        obj.parent.removeChild(obj.children [I]);
                    }
                })
            }
        });
    }

},1000);

//闪烁星星动画 
setInterval(function() {
     const obj = addChild(“#stars”,“div”,2,“blink”);

    for(let i = 0 ; i <obj.children.length; i ++){
         const top = -50 + Math .random()* 500 + “px”,
            left = 200 + Math .random()* 1200 + “px”,
            round = 1 + Math .random()* 2 + “px” ;
        const timer = 1000 + Math .random()* 4000 ;

        obj.children [i] .style.top = top;
        obj.children [i] .style.left = left;
        obj.children [i] .style.width = round;
        obj.children [i] .style.height = round;

        requestAnimation({
            ele:obj.children [i],
             attr:“opacity”,
             值:.5,
             time:timer,
             flag:false,
             fn:function() {
                requestAnimation({
                    ele:obj.children [i],
                     attr:“opacity”,
                     value:0,
                     time:timer,
                     flag:false,
                     fn:function() {
                        obj.parent.removeChild(obj.children [I]);
                    }
                });
            }
        });
    }

},1000);

//月亮移动
requestAnimation({
    ele:“#moon”,
     attr:“right”,
     值:1200,
     时间:10000000,
});

//添加云
const clouds = addChild(“。cloud”,“div”,14,“circle”,true);
for(let i = 0 ; i <clouds.children.length; i ++){
     for(let j = 0 ; j <clouds.children [i] .length;){
        clouds.children [i] [j] .classList.add(`circle- $ {++ j} `);
    }
}
//云动画

let flag = 1 ;
的setInterval(
    功能() {
         const clouds = document .querySelectorAll(“。cloud”);
        const left = Math .random()* 5 ;
        bottom = Math .random()* 5 ;

        let timer = 0 ;
        for(let i = 0 ; i <clouds.length; i ++){
            requestAnimation({
                ele:clouds [i],
                 attr:[ “left”,“bottom” ],
                 value:flag%2?[-left,-bottom]:[left,bottom],
                 time:timer + = 500,
                 flag:false,
                 fn:function() {
                    requestAnimation({
                        ele:clouds [i],
                         attr:[ “left”,“bottom” ],
                         value:flag%2?[left,bottom]:[ -  left,-bottom],
                         time:timer,
                         flag:false
                    })
                }
            });
        }

        标志++;
    },2000)

梱包方法

// -------------------------------------------动画---- ----------------------------------------------- 
//运动动画,调用Tween.js 
// ele:dom | 班级| id | 标签节点| 类名| id名| 标签名,只支持选择一个节点,类类名以及标签名只能选择页面中第一个
// attr:属性属性名
//值:目标值目标值
//时间:持续时间持续时间
//补间:定时function函数方程
// flag:Boolean判断是按值移动还是按位置移动,默认按位置移动
// fn:callback回调函数
//增加返回值:将内部参数对象返回,可以通过设置返回对象的属性stop为true打断动画
函数 requestAnimation(obj) {
     // -------------------------------------参数设置--------------------------------------------- 
    //默认属性
    const参数= {
         ele:null,
         attr:null,
         value:null,
         time:1000,
         tween:“linear”,
         flag:true,
         stop:false,
         fn:“”
    }

    //合并传入属性
    Object .assign(parameter,obj); //覆盖重名属性

    // -------------------------------------动画设置--------- ------------------------------------ 
    //创建运动方程初始参数,方便复用
    let start = 0 ; //用于保存初始时间戳
    let target =(typeof parameter.ele === “string”?document .querySelector(parameter.ele):parameter.ele),//目标节点 
        attr = parameter.attr,//目标属性 
        beginAttr = parseFloat(getComputedStyle(target)[attr]),// attr起始值 
        value = parameter.value,//运动目标值 
        count = value  -  beginAttr,//实际运动值 
        time = parameter.time,//运动持续时间,
        tween = parameter.tween,//运动函数
        flag = parameter.flag,
        callback = parameter.fn,//回调函数 
        curVal = 0 ; //运动当前值

    //判断传入函数是否为数组,多段运动 
    (function() {
         if(attr instanceof  Array){
            beginAttr = [];
            count = [];
            对于(让我的 ATTR){
                 常量 VAL = parseFloat(的getComputedStyle(目标)[I]);
                beginAttr.push(VAL);
                count.push(value  -  val);
            }
        }
        if(value instanceof  Array){
             for(let i in value){
                count [i] = value [i]  -  beginAttr [i];
            }
        }
    })();

    //运动函数
    功能 动画(时间戳) {
         如果(parameter.stop)返回 ; //打断
        //存储初始时间戳
        if(!start)start = timestamp;
        //已运动时间
        让 t =时间戳 - 开始;
        //判断多段运动
        if(beginAttr instanceof  Array){
             // const len = beginAttr.length //存数组长度,复用

            //多段运动第1类 - 多属性,同目标,同时间/不同时间
            if(typeof count === “number”){ //同目标
                //同时间
                if(typeof time === “number”){
                     if(t> time)t = time; //判断是否超出目标值

                    //循环attr,分别赋值
                    为(let i in beginAttr){
                         if(flag)curVal = Tween [tween](t,beginAttr [i],count,time); //调用Tween,返回当前属性值,此时计算方法为移动到
                        写入位置else curVal = Tween [tween](t,beginAttr [i],count + beginAttr [i],time); //调用Tween,返回当前属性值,此时计算方法为移动了
                        写入距离if(attr [i] === “opacity”)target.style [attr [i]] = curVal; //给属性赋值
                        else target.style [attr [i]] = curVal + “px” ; //给属性赋值

                        if(t <time)requestAnimationFrame(animate); //判断是否运动完
                        其他回调&& callback(); //调用回调函数
                    }
                    回归 ;
                }

                //不同时间
                if(time instanceof  Array){
                     //循环时间,attr,分别赋值
                    为(让我在 beginAttr中){
                         //错误判断
                        if(!time [i] && time [i]!== 0){
                             throw  new  Error(
                                 “输入时间的长度不等于属性的长度”);
                        }

                        //判断是否已经完成动画,完成则跳过此次循环
                        if(parseFloat(getComputedStyle(target)[attr [i]])===(typeof value === “number”?value:value [i]) )
                             继续 ;
                        // t =时间戳 - 开始; //每次循环初始化t 
                        if(t> time [i])t = time [i]; //判断是否超出目标值

                        if(flag || attr [i] === “opacity”)curVal = Tween [tween](t,beginAttr [i],count,i); //调用Tween,返回当前属性值,此时计算方法为移动到
                        写入位置else curVal = Tween [tween](t,beginAttr [i],count + beginAttr [i],i); //调用Tween,返回当前属性值,此时计算方法为移动了
                        写入距离if(attr [i] === “opacity”)target.style [attr [i]] = curVal; //给属性赋值
                        else target.style [attr [i]] = curVal + “px” ; //给属性赋值
                    }

                    if(t < Math .max(... time))requestAnimationFrame(animate); //判断函数是否运动完
                    其他回调&& callback(); //如果已经执行完时间最长的动画,则调查回调函数
                    return ;
                }
            }

            //多段运动第2类 - 多属性,不同目标,同时间/不同时间
            if(count instanceof  Array){
                 //同时间
                if(typeof time === “number”){

                    if(t> time)t = time; //判断是否超出目标值

                    for(let i in beginAttr){ //循环attr,count,分别赋值
                        //错误判断
                        if(!count [i] && count [i]!== 0){
                             throw  new  Error(
                                 “输入值的长度不是等于属性的长度“);
                        }

                        if(flag || attr [i] === “opacity”)curVal = Tween [tween](t,beginAttr [i],count [i],time); //调用Tween,返回当前属性值,此时计算方法为移动到
                        写入位置else curVal = Tween [tween](t,beginAttr [i],count [i] + beginAttr [i],time); //调用Tween,返回当前属性值,此时计算方法为移动了
                        写入距离if(attr [i] === “opacity”)target.style [attr [i]] = curVal; //给属性赋值
                        else target.style [attr [i]] = curVal + “px” ; //给属性赋值
                    }

                    if(t <time)requestAnimationFrame(animate); //判断函数是否运动完
                    其他回调&& callback(); //如果已经执行完时间最长的动画,则调查回调函数
                    return ;
                }

                //不同时间
                if(time instanceof  Array){
                     for(let i in beginAttr){
                         //错误判断
                        if(!time [i] && time [i]!== 0){
                             throw  new  Error(
                                 “输入时间的长度)不等于属性的长度“);
                        }

                        //判断是否已经完成动画,完成则跳过此次循环
                        if(parseFloat(getComputedStyle(target)[attr [i]])===(typeof value === “number”?value:value [i]) )
                             继续 ;

                        if(t> time [i])t = time [i]; //判断是否超出目标值

                        //错误判断
                        if(!count [i] && count [i]!== 0){
                             throw  new  Error(
                                 “输入值的长度不等于属性的长度”);
                        }

                        if(flag || attr [i] === “opacity”)curVal = Tween [tween](t,beginAttr [i],count [i],time [i]); //调用Tween,返回当前属性值,此时计算方法为移动到
                        写入位置其他 curVal = Tween [tween](t,beginAttr [i],count [i] + beginAttr [i],time [i]) ; //调用Tween,返回当前属性值,此时计算方法为移动了
                        写入距离if(attr [i] === “opacity”)target.style [attr [i]] = curVal;
                        否则 target.style [attr [i]] = curVal + “px” ;
                    }

                    if(t < Math .max(... time))requestAnimationFrame(animate);
                    else callback && callback();
                    回归 ;
                }
            }

        }

        //单运动模式
        if(t> time)t = time;
        if(flag || attr === “opacity”)curVal = Tween [tween](t,beginAttr,count,time); //调用Tween,返回当前属性值,此时计算方法为移动到
        写入位置else curVal = Tween [tween](t,beginAttr [i],count + beginAttr,time); //调用Tween,返回当前属性值,此时计算方法为移动了
        写入距离if(attr === “opacity”)target.style [attr] = curVal;
        否则 target.style [attr] = curVal + “px” ;

        if(t <time)requestAnimationFrame(animate);
        else callback && callback();

    }

    requestAnimationFrame(动画);
    返回参数; //返回对象,供打断或其他用途
}
//Tween.js 
/ *
 * t:时间已过时间
 * b:开始起始值
 * c:计算总的运动值
 * d:持续时间持续时间
 *
 *曲线方程
 *
 * http://www.cnblogs.com/bluedream2009/archive/2010/06/19/1760909.html
 * * /

让 Tween = {
     linear:function(t,b,c,d) { //匀速
        返回 c * t / d + b;
    },
    easeIn:function(t,b,c,d) { //加速曲线
        return c *(t / = d)* t + b;
    },
    easeOut:function(t,b,c,d) { //减速曲线
        return -c *(t / = d)*(t  - 2)+ b;
    },
    easeBoth:function(t,b,c,d) { //加速减速曲线
        if((t / = d / 2)< 1){
             return c / 2 * t * t + b;
        }
        return -c / 2 *(( -  t)*(t  - 2) - 1)+ b;
    },
    easeInStrong:function(t,b,c,d) { //加加速曲线
        return c *(t / = d)* t * t * t + b;
    },
    easeOutStrong:function(t,b,c,d) { //减减曲线
        返回 -c *((t = t / d  - 1)* t * t * t  - 1)+ b;
    },
    easeBothStrong:function(t,b,c,d) { //加速减减速线
        如果((t / = d / 2)< 1){
             return c / 2 * t * t * t * t + b;
        }
        return -c / 2 *((t  -  = 2)* t * t * t  - 2)+ b;
    },
    elasticIn:function(t,b,c,d,a,p) { //正弦衰减曲线(弹动渐入)
        if(t === 0){
             return b;
        }
        if((t / = d)== 1){
             return b + c;
        }
        if(!p){
            p = d * 0.3 ;
        }
        if(!a || a < Math .abs(c)){
            a = c;
            var s = p / 4 ;
        } else {
             var s = p /(2 * Math .PI)* Math .asin(c / a);
        }
        返回 - (A * 数学 .pow(2,10 *(T - = 1))* 数学 .sin((T * d - S)*(2 * 数学 .PI)/ P))+ B;
    },
    elasticOut:function(t,b,c,d,a,p) { //正弦增强曲线(弹动渐出)
        if(t === 0){
             return b;
        }
        if((t / = d)== 1){
             return b + c;
        }
        if(!p){
            p = d * 0.3 ;
        }
        if(!a || a < Math .abs(c)){
            a = c;
            var s = p / 4 ;
        } else {
             var s = p /(2 * Math .PI)* Math .asin(c / a);
        }
        返回 a * Math .pow(2,-10 * t)* Math .sin((t * d  -  s)*(2 * Math .PI)/ p)+ c + b;
    },
    elasticBoth:function(t,b,c,d,a,p) {
         if(t === 0){
             return b;
        }
        if((t / = d / 2)== 2){
             return b + c;
        }
        if(!p){
            p = d *(0.3 * 1.5);
        }
        if(!a || a < Math .abs(c)){
            a = c;
            var s = p / 4 ;
        } else {
             var s = p /(2 * Math .PI)* Math .asin(c / a);
        }
        如果(T < 1){
             返回 -0.5 *(A * 数学 .pow(2,10 *(T - = 1))*
                 数学 .sin((T * d - S)*(2 * 数学 .PI)/ p))+ b;
        }
        返回 a * Math .pow(2,-10 *(t  -  = 1))*
             Math .sin((t * d  -  s)*(2 * Math .PI)/ p)* 0.5 + c + b;
    },
    backIn:function(t,b,c,d,s) { //回退加速(回退渐入)
        if(typeof s == 'undefined'){
            s = 1.70158 ;
        }
        return c *(t / = d)* t *((s + 1)* t  -  s)+ b;
    },
    backOut:function(t,b,c,d,s) {
         if(typeof s == 'undefined'){
            s = 3.70158 ; //回缩的距离
        }
        return c *((t = t / d  - 1)* t *((s + 1)* t + s)+ 1)+ b;
    },
    backBoth:function(t,b,c,d,s) {
         if(typeof s == 'undefined'){
            s = 1.70158 ;
        }
        if((t / = d / 2)< 1){
             return c / 2 *(t * t *(((s * =(1.525))+ 1)* t  -  s))+ b;
        }
        return c / 2 *((t  -  = 2)* t *(((s * =(1.525))+ 1)* t + s)+ 2)+ b;
    },
    bounceIn:function(t,b,c,d) { //弹球渐出)
        返回 c  -  Tween [ 'bounceOut' ](d  -  t,0,c,d)+ b;
    },
    bounceOut:function(t,b,c,d) {
         if((t / = d)<(1 / 2.75)){
             return c *(7.5625 * t * t)+ b;
        } else  if(t <(2 / 2.75)){
             return c *(7.5625 *(t  -  =(1.5 / 2.75))* t + 0.75)+ b;
        } else  if(t <(2.5 / 2.75)){
             return c *(7.5625 *(t  -  =(2.25 / 2.75))* t + 0.9375)+ b;
        }
        return c *(7.5625 *(t  -  =(2.625 / 2.75))* t + 0.984375)+ b;
    },
    bounceBoth:函数(T,B,C,d) {
         如果(T <d / 2){
             返回吐温[ 'bounceIn' ](T * 2,0,C,d)* 0.5 + B;
        }
        return Tween [ 'bounceOut' ](t * 2 -  d,0,c,d)* 0.5 + c * 0.5 + b;
    }
}

// ------------------------------------------- DOM操作--- ------------------------------------------------ 
//添加节点
// ele:父节点,支持输入变量,id值,类值,标签值。除变量外,其余值必须为字符串
//节点:添加的标签名,值为字符串
// n:节点添加个数
// className:节点绑定的类名,值为字符串,多个类名用空格隔开
//布尔:是否选中所有目标父节点。可选参数,不输入则判定为false,则只匹配选中的第一个节点
函数 addChild(ele,node,n,className,boolean) {
     //获取节点
    let parent = null ;

    if(typeof ele!== “string”)parent = ele;
    else  if(ele [ 0 ] === “#”)parent = document .getElementById(ele.slice(1));
    else  if(ele [ 0 ] === “。”){
         if(boolean === false)parent = document .getElementsByClassName(ele.slice(1))[ 0 ];
        else parent = document .getElementsByClassName(ele.slice(1));
    } else {
         if(boolean === false)parent = docuemnt.getElementsByTagName(ele)[ 0 ];
        else parent = document .getElementsByTagNameNS(ele);
    }

    //声明用于存储父节点及子节点的对象
    const obj = {
         “parent”:parent,
         “children”:[]
    };

    //添加节点
    if(boolean){
         for(let i = 0 ; i <parent.length; i ++){
             //创建容器碎片
            const fragment = document .createDocumentFragment();
            //保存子节点,用于返回值
            obj.children [i] = [];

            for(let j = 0 ; j <n; j ++){
                 const target = document .createElement(node);
                target.className = className;
                fragment.appendChild(目标);
                //添加子节点到数组,用于返回值
                obj.children [i] [j] =目标;
            }

            父[I] .appendChild(片段)
        }
    } else {
         //创建碎片容器
        const fragment = document .createDocumentFragment();

        for(let i = 0 ; i <n; i ++){
             const target = document .createElement(node);
            target.className = className;
            fragment.appendChild(目标);
            //添加子节点,用于返回值
            obj.children [i] =目标;
        }
        //将碎片容器一次性添加到父节点
        parent.appendChild(片段);
    }

    //返回参数,供动画函数调用
    return obj;
}

3、ケース分析

HTML

ノード番号ので、私は、少し現実的な面白いことをしようランダムな場所に戻ってノードを追加します。したがって、出力ノードはJSで制御され、ここでHTMLは構造が比較的単純で、クラスの対応するIDとクラス名を使用して、親ボックスのほんの数の要素を記述します。

CSS

難しCSSスタイルの一部には、雲やビデオ円、その後、3次元効果の雲スタックと流星です。

流星のスタイルについての最初の話:

#sky  .star {
      position:absolute;
     不透明度:0 ;
     z-index:10000 ;
 }

 .star :: after {
      content:“” ;
     显示:块;
     边界:坚固;
     border-width:2px  0  2px  80px ;
     / *流星随长度逐渐缩小* / 
     border-color:透明透明透明rgba(255,255,255,1);
     border-radius:2px  0  0  2px ;
     transform:rotate(-45deg);
     transform-origin:0  0  0 ;
     盒子阴影:0  0  20px  rgba(255,255,255,.3);
 }
web前端开发学习Q-q-u-n: 784783012 ,分享学习的方法和需要注意的小细节,不停更新最新的教程和学习方法(详细的前端项目实战教学视频)

まず、一般的なスタイルを抽出し、位置決め属性を追加します。

次に、特性ペイントされたボーダーで、擬似クラスを通じてスター流星を追加した後:

上面の四辺のオーダーの境界幅、右、左下、ボーダー色の順序と同じ方法で、トップの四辺のために、右、下、左:1)モデルを描画。このような対応が完了したら、2ピクセルの境界幅は、ボーダー色流星、流星80px長さの幅で見ることができ、そしてピクセル0は、このように形成テール流星です。2ピクセル幅の広い頭部、尾0ピクセル、流星モデル80pxの長さ。

2)やや現実的:ボーダー半径によって?流星が落ちるように見え、それがrotetaによって回転のより現実的な最終角度を見えるように、丸い頭に増加しました。

3)フラッシュを増やす:点滅の効果を持っているように見えます、ハローシャドーボックスで流星にビットを追加します。

上記の3つのステップでは、流星は良く描画します。

そして、絵が行きます:

クラウド長いコードなので、ここでの方法は、仕上げフォームの雲を、1ラウンド以上何によって投稿されていないカバーを重ね合わせています。
雲が完了した後、コピーは、その後、雲の複数を介して重畳斜視フェード効果を作るために、不透明度、左位置決め、回転します。

JS

流星を説明するためのJSセクション

setInterval(function() {
     const obj = addChild(“#sky”,“div”,2,“star”); //插入流星

    for(let i = 0 ; i <obj.children.length; i ++){
         //随机位置
        const top = -50 + Math .random()* 200 + “px”,
            left = 200 + Math .random()* 1200 + “px”,
            scale = 0.3 + Math .random()* 0.5 ;
        const timer = 1000 + Math .random()* 1000 ;

        obj.children [i] .style.top = top;
        obj.children [i] .style.left = left;
        obj.children [i] .style.transform = `scale($ {scale})` ;

        //添加动画
        requestAnimation({
            ele:obj.children [i],
             attr:[ “top”,“left”,“opacity” ],
             值:[ 150,-150,.8 ],
             time:timer,
             flag:false,
             fn:function() {
                requestAnimation({
                    ELE:obj.children [I],
                     ATTR:“顶”,“左”,“不透明” ],
                     值:[ 150,-150,0 ],
                     时间:定时器,
                     标志:假,
                     FN:() => {
                        obj.parent.removeChild(obj.children [I]); //动画结束删除节点
                    }
                })
            }
        });
    }

},1000);
web前端开发学习Q-q-u-n: 731771211,分享学习的方法和需要注意的小细节,不停更新最新的教程和学习方法(详细的前端项目实战教学视频)

この辺はのappendChildにaddChildに基づいてrequestAnimationのrequestAnimationFrameの、に基づいて、私自身のパッケージの2つのメソッドを使用します。

挿入したsetIntervalタイマー流星を削除し続けることで、ランダム効果の星の位置を達成するために:

まず第一に、毎回次の2個の流星にページを追加しますが、インターバルタイマー撮影スターのアニメーション時間未満なので、我々は流星のページ数が固定値ではありません保証することができますが、それは確かに2以上です。それ以外の場合は、2個の流星は孤独なビット。

流星ランダム位置(上、左)、ランダムサイズ(サイズに追加される新しい各ページに - そして、循環を介して(最も単純な式でも、すべての行について、のために、使用することができます) )、ランダムアニメーション実行時間(タイマー)。

最後に、ループ内で、それぞれの新しいページにアニメーションを追加し、コールバック関数を介してアニメーションを実行した後、ノードを削除流星に加えます。ここでは、(表示され、消えて、主に不透明度コントロール)アニメーションへの2つのフェーズに分け、ことに注意しなければなりません。また、私はここに対処する、すべての流星が同じ距離300ピクセルを移動している、しませんが、私はこの距離でも乱数によって制御することができると思いますが、私は怠け者を作りました。

4、小さな問題

現在、私は2つを発見した問題があります。

DOM操作自体は常に絶えず、その結果、ノードを追加および削除する一つの問題ページ。そして逆流、パフォーマンスの廃棄物を再描画します。

第二に、問題自体requestAnimationFrameのタイマーが常にノードを追加するので、requestAnimationFrameの機能ながら - 他のページを閲覧するために、現在のページを離れるとき、アニメーションが中断されます。これは、ノードが追加されている問題を作成しますが、フルストップ実行中のアニメーションは、このページへの復帰次回がないように、それはブームを爆発する!アニメーションを、あなたは絵カードが表示されます、多くのオタマジャクシ集団行動は、彼女の母親を見つけるために。

5.まとめ

この場合は、ビューの点から非常に単純な少し難しいですが、それは非常に高い開発することができますが - など、そのような白いああのテーブルとしてアカシアを送信する、ロマンチックなああを再生し、また、純粋なCSSを使用して達成することができます。

おすすめ

転載: blog.51cto.com/14592820/2447317