如何实现一个惊艳女友的血轮眼轮回眼特效

前端瓶子君

共 48970字,需浏览 98分钟

 ·

2021-05-09 03:24

点击上方 前端瓶子君,关注公众号

回复算法,加入前端编程面试算法每日一题群

效果(完整代码在底部):

实现并不难,都是重复的代码比较多。

实现(可跟着一步一步写):

1. 先定义基本标签:

<!-- 血轮眼 -->
    <div class="zuo">
        <!-- 眼睛最中间那个黑点 -->
        <div class="zuoZong">
            <!-- 三勾玉所在的圈 -->
            <div class="zuoYu">
                <!-- 三个勾玉 -->
                <span class="yu"></span>
                <span class="yu"></span>
                <span class="yu"></span>
            </div>
        </div>
    </div>
    <!-- 轮回眼 -->
    <div class="you">
        <!-- 眼睛最中间那个黑点 -->
        <div class="dian"></div>
             <!-- 3个轮回圈 -->
            <div class="youYu">                        
                <span class="quan" style="--r:2;"></span>
                <span class="quan" style="--r:3;"></span>
                <span class="quan" style="--r:4;"></span>
            </div>       
    </div>

2. 定义左右眼的基本css样式:

.zuo , .you
            width250px;
            height120px;
            background-colorrgb(255255255);
            border-bottom5px solid rgb(707070);
            overflow: hidden;
            position: relative;
        }

border-bottom: 5px solid rgb(70, 70, 70); 给个灰色的眼底。overflow:溢出隐藏。position: relative; 相对定位。

3. 开始先定义血轮眼的基本样式:

.zuo{
            transformtranslateX(-135px);
            border-radius0 120px 0 120px;
            box-shadow: inset 3px 2px 3px  rgba(1717170.8);
        }

transform: translateX(-135px); 向左偏移,让两眼分开。border-radius:给两个角设置弧度,形成眼睛形状。bos-shadowL给眼角一点阴影。

4. 设置眼球宽高等:

.zuo::after{
            content'';
            position: absolute;
            top50%;
            left50%;
            transformtranslate(-50%,-50%);
            width95px;
            height95px;
            border-radius50%;
            border2px solid #000;
            animation: colour 2s linear forwards;
        }
        @keyframes colour{
            0%,30%{
                background-colorrgb(000);
            }
            100%{
                 background-colorrgb(25544);
             }
         }

position: absolute; 绝对定位 top: 50%; left: 50%; transform: translate(-50%,-50%); 居中对齐。animation:设置动画,让其变红色。forward:继承最后一帧的属性。background-color: rgb(0, 0, 0); 黑色 background-color: rgb(255, 4, 4); 红色。

5. 设置眼球正中间的黑点,都是些定位大小啥的,然后设置动画然它慢慢变大:

 .zuoZong{
            position: absolute;
            top50%;
            left50%;
            transformtranslate(-50%,-50%);
            width0px;
            height0px;
            border-radius50%;
            background-colorrgb(000);
            z-index1;
            animation: da 3s linear forwards;
        }
        @keyframes da{
            100%{
                width15px;
            height15px;
            }
        }

6. 设置三勾玉所在的圈,设置动画让其显示与旋转:

.zuoYu{
            position: absolute;
            top: -25px;
            left: -25px;
            bottom: -25px;
            right: -25px;
            border-radius50%;
            border2px solid rgb(000);
            animation: zhuan 2s linear 2s forwards;
            opacity0;
        }
        @keyframes zhuan{
           
            100%{
                opacity1;
                transformrotate(720deg);
            }
        }

position: absolute; top: -25px; left: -25px; bottom: -25px; right: -25px; 大小。border-radius: 50%;圆形。border: 2px solid rgb(0, 0, 0); 黑色边框。opacity:0;透明度为0;transform: rotate(720deg); 旋转720度。

7. 制作三勾玉,先做一个圆,再用双伪类制作一个圆弧,两者结合就是勾玉了:

.zuoYu .yu{
             position: absolute;
             width15px;
             height15px;
             border-radius50%;
             background-colorrgb(000);

        }
        .zuoYu .yu::after{
            content'';
            position: absolute;
            top: -6px;
            left: -1px;
            width6px;
            height20px;
            border-radius50%;
            border-left6px solid rgb(000);
        }

border-radius: 50%; border-left: 6px solid rgb(0, 0, 0); 先让伪类为圆,再只设置一条边框,圆弧形成,再定位在父元素上,形成勾玉。

8. 给勾玉设置动画,让其从最中间变大旋转到勾玉所在的圈:

  .zuoYu .yu:nth-child(1){
            animation: yu1 2s ease-in 2s  forwards;
        }
        @keyframes yu1{
            0%{
                opacity0;
                left50%;
                top50%;                
                transform:translate(-50%,-50%)  scale(0.1) ;
            }
            100%{
                left50%;
                top: -9%;
                transformscale(1rotate(80deg);  
            }
        }     

left: 50%; top: 50%; 在最中间。opacity:透明。scale(0.1);缩小。100%{..}到对应位置,同时变不透明和放大成正常大小。

9. 一样的,给其它两个勾玉动画:

.zuoYu .yu:nth-child(2){
            animation: yu2 2s ease-in 2s forwards; 
        }
        @keyframes yu2{
            0%{
                opacity0;
                left50%;
                top50%;
                
                transformtranslate(-50%,-50%scale(0.1) ;
            }
            100%{
                top60%;
                left: -9%;
                transformscale(1rotate(-60deg);  
            }
        }
        .zuoYu .yu:nth-child(3){          
            animation: yu3 2s ease-in 2s forwards;
        }
        @keyframes yu3{
            0%{
                opacity0;
                right50%;
                top50%;
                
                transformtranslate(-50%,-50%scale(0.1);
            }
            100%{
                top60%;
                right: -9%;
                transformscale(1rotate(180deg);  
            }
        }

10.给两个眼睛都设置一个白点,相当于反光效果吧,至此血轮眼做完了:

.zuo::before,.you::before{
            content'';
            position: absolute;
            left38%;
            top30%;
            width12px;
            height12px;
            border-radius50%;
            background-colorrgb(255255255);
            z-index10;
        }

position: absolute; left: 38%; top: 30%; 定位相应的位置。background-color: rgb(255, 255, 255); 白色。z-index: 10; 设置为10,显示在最上层。

11.设置轮回眼基本css样式,跟血轮眼一样:

 .you{
            transformtranslateX(135px);
            border-radius:  120px 0 120px 0;
            box-shadow: inset -3px 2px 3px  rgba(1717170.8);
        }

12.设置眼球宽高等:

.you::after{
            content'';
            position: absolute;
            top50%;
            left50%;
            transformtranslate(-50%,-50%);
            width95px;
            height95px;
            border-radius50%;
            border2px solid #000;
            animation: youcolor 2s linear forwards;
         }
         @keyframes youcolor{
            0%,30%{
                background-colorrgb(000);
            }
            100%{
                 background-colorrgb(144130183);
             
             }
         }

position: absolute; 绝对定位 top: 50%; left: 50%; transform: translate(-50%,-50%); 居中对齐。animation:设置动画,让其变紫色。forward:继承最后一帧的属性。background-color: rgb(0, 0, 0); 黑色 background-color: rgb(144, 130, 183); 紫色。

13. 设置眼球最中间的黑点,跟血轮眼也差不多:

.dian{       
             position: absolute;
            top50%;
            left50%;              
            background-color#000;
            transformtranslate(-50%,-50%);
            border-radius50%;
            z-index10;
            animation: youda 3s linear forwards;
         }
         @keyframes youda{
             0%{
                height0px;
            width0px;
             }
             100%{
                height15px;
            width15px;
             }
         }

14. 设置轮回眼每个圈,同时设置动画让其变大:

 .youYu{
            position: absolute;
          top50%;
          left50%;
          transformtranslate(-50%,-50%);
       }
       .quan{
           position: absolute;
           border-radius50%;
           border2px solid #000;
           z-indexcalc(1 - var(--r));
           animation: zhi 2s ease-out 2s forwards;
       }
       @keyframes zhi{
           0%{
            topcalc(var(--r) * 1px);
           leftcalc(var(--r) * 1px);
           rightcalc(var(--r) * 1px);
           bottomcalc(var(--r) * 1px);
           }
           100%{
            topcalc(var(--r) * -35px);
           leftcalc(var(--r) * -35px);
           rightcalc(var(--r) * -35px);
           bottomcalc(var(--r) * -35px);

               background-colorrgb(187177214);
           }
       }

z-index: calc(1 - var(--r)); 计算,让最开始的圈显示在最上层。animation:设置动画,让轮回圈慢慢变大,同时变成紫色。

完整代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin0;
            padding0;
            box-sizing: border-box;
        }
        body{
            height100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color#000;
        }
        .zuo , .you
            width250px;
            height120px;
            background-colorrgb(255255255);
            border-bottom5px solid rgb(707070);
            overflow: hidden;
            position: relative;
        }
         
        .zuo{
            transformtranslateX(-135px);
            border-radius0 120px 0 120px;
            box-shadow: inset 3px 2px 3px  rgba(1717170.8);
        }
        .zuo::after{
            content'';
            position: absolute;
            top50%;
            left50%;
            transformtranslate(-50%,-50%);
            width95px;
            height95px;
            border-radius50%;
            border2px solid #000;
            animation: colour 2s linear forwards;
        }
        @keyframes colour{
            0%,30%{
                background-colorrgb(000);
            }
            100%{
                 background-colorrgb(25544);
             }
         }

        .zuoZong{
            position: absolute;
            top50%;
            left50%;
            transformtranslate(-50%,-50%);
            width0px;
            height0px;
            border-radius50%;
            background-colorrgb(000);
            z-index1;
            animation: da 3s linear forwards;
        }
        @keyframes da{
            100%{
                width15px;
            height15px;
            }
        }
        .zuoYu{
            position: absolute;
            top: -25px;
            left: -25px;
            bottom: -25px;
            right: -25px;
            border-radius50%;
            border2px solid rgb(000);
            animation: zhuan 2s linear 2s forwards;
            opacity0;
        }
        @keyframes zhuan{
           
            100%{
                opacity1;
                transformrotate(720deg);
            }
        }
        .zuoYu .yu{
             position: absolute;
             width15px;
             height15px;
             border-radius50%;
             background-colorrgb(000);

        }
        .zuoYu .yu::after{
            content'';
            position: absolute;
            top: -6px;
            left: -1px;
            width6px;
            height20px;
            border-radius50%;
            border-left6px solid rgb(000);
        }
        .zuoYu .yu:nth-child(1){
            animation: yu1 2s ease-in 2s  forwards;
        }
        @keyframes yu1{
            0%{
                opacity0;
                left50%;
                top50%;
                
                transform:translate(-50%,-50%)  scale(0.1) ;
            }
            100%{
                left50%;
                top: -9%;
                transformscale(1rotate(80deg);  
            }
        }       
        .zuoYu .yu:nth-child(2){
            animation: yu2 2s ease-in 2s forwards; 
        }
        @keyframes yu2{
            0%{
                opacity0;
                left50%;
                top50%;
                
                transformtranslate(-50%,-50%scale(0.1) ;
            }
            100%{
                top60%;
                left: -9%;
                transformscale(1rotate(-60deg);  
            }
        }
        .zuoYu .yu:nth-child(3){          
            animation: yu3 2s ease-in 2s forwards;
        }
        @keyframes yu3{
            0%{
                opacity0;
                right50%;
                top50%;
                
                transformtranslate(-50%,-50%scale(0.1);
            }
            100%{
                top60%;
                right: -9%;
                transformscale(1rotate(180deg);  
            }
        }
        .zuo::before,.you::before{
            content'';
            position: absolute;
            left38%;
            top30%;
            width12px;
            height12px;
            border-radius50%;
            background-colorrgb(255255255);
            z-index10;
        }
        .you{
            transformtranslateX(135px);
            border-radius:  120px 0 120px 0;
            box-shadow: inset -3px 2px 3px  rgba(1717170.8);
/*             filter: drop-shadow( 8px -5px 3px  rgb(216, 59, 59));
 */
        }
         .you::after{
            content'';
            position: absolute;
            top50%;
            left50%;
            transformtranslate(-50%,-50%);
            width95px;
            height95px;
            border-radius50%;
            border2px solid #000;
            animation: youcolor 2s linear forwards;
         }
         @keyframes youcolor{
            0%,30%{
                background-colorrgb(000);
            }
            100%{
                 background-colorrgb(144130183);
             
             }
         }
         
         .dian{       
             position: absolute;
            top50%;
            left50%;              
            background-color#000;
            transformtranslate(-50%,-50%);
            border-radius50%;
            z-index10;
            animation: youda 3s linear forwards;
         }
         @keyframes youda{
             0%{
                height0px;
            width0px;
             }
             100%{
                height15px;
            width15px;
             }
         }
         .youYu{
            position: absolute;
          top50%;
          left50%;
          transformtranslate(-50%,-50%);
       }
       .quan{
           position: absolute;
           border-radius50%;
           border2px solid #000;
           z-indexcalc(1 - var(--r));
           animation: zhi 2s ease-out 2s forwards;
       }
       @keyframes zhi{
           0%{
            topcalc(var(--r) * 1px);
           leftcalc(var(--r) * 1px);
           rightcalc(var(--r) * 1px);
           bottomcalc(var(--r) * 1px);
           }
           100%{
            topcalc(var(--r) * -35px);
           leftcalc(var(--r) * -35px);
           rightcalc(var(--r) * -35px);
           bottomcalc(var(--r) * -35px);

               background-colorrgb(187177214);
           }
       }
    </style>

</head>
<body>
    <!-- 血轮眼 -->
    <div class="zuo">
        <!-- 眼睛最中间那个黑点 -->
        <div class="zuoZong">
            <!-- 三勾玉所在的圈 -->
            <div class="zuoYu">
                <!-- 三个勾玉 -->
                <span class="yu"></span>
                <span class="yu"></span>
                <span class="yu"></span>
            </div>
        </div>
    </div>
    <!-- 轮回眼 -->
    <div class="you">
        <!-- 眼睛最中间那个黑点 -->
        <div class="dian"></div>
             <!-- 3个轮回圈 -->
            <div class="youYu">                        
                <span class="quan" style="--r:2;"></span>
                <span class="quan" style="--r:3;"></span>
                <span class="quan" style="--r:4;"></span>
            </div>       
    </div>
</body>
</html>

其它:

血轮眼,开~

热烈宣布(敲锣打鼓,手舞足蹈),我的B站账号地址:space.bilibili.com/176586698

泪目( Ĭ ^ Ĭ )

转载自:北极光之夜

https://juejin.cn/post/6955052354664136712

最后

欢迎关注【前端瓶子君】✿✿ヽ(°▽°)ノ✿
回复「算法」,加入前端编程源码算法群,每日一道面试题(工作日),第二天瓶子君都会很认真的解答哟!
回复「交流」,吹吹水、聊聊技术、吐吐槽!
回复「阅读」,每日刷刷高质量好文!
如果这篇文章对你有帮助,在看」是最大的支持
》》面试官也在看的算法资料《《
“在看和转发”就是最大的支持
浏览 21
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报