[前端] html+css实现血轮眼轮回眼特效代码

1681 0
黑夜隐士 2022-10-19 15:30:29 | 显示全部楼层 |阅读模式
效果(完整代码在底部):


实现并不难,都是重复的代码比较多。
实现(可跟着一步一步写):
1. 先定义基本标签:
  1. <!-- 血轮眼 -->
  2.     <div class="zuo">
  3.         <!-- 眼睛最中间那个黑点 -->
  4.         <div class="zuoZong">
  5.             <!-- 三勾玉所在的圈 -->
  6.             <div class="zuoYu">
  7.                 <!-- 三个勾玉 -->
  8.                 <span class="yu"></span>
  9.                 <span class="yu"></span>
  10.                 <span class="yu"></span>
  11.             </div>
  12.         </div>
  13.     </div>
  14.     <!-- 轮回眼 -->
  15.     <div class="you">
  16.         <!-- 眼睛最中间那个黑点 -->
  17.         <div class="dian"></div>
  18.              <!-- 3个轮回圈 -->
  19.             <div class="youYu">                        
  20.                 <span class="quan" style="--r:2;"></span>
  21.                 <span class="quan" style="--r:3;"></span>
  22.                 <span class="quan" style="--r:4;"></span>
  23.             </div>      
  24.     </div>
复制代码
2. 定义左右眼的基本css样式:
  1. .zuo , .you{
  2.             width: 250px;
  3.             height: 120px;
  4.             background-color: rgb(255, 255, 255);
  5.             border-bottom: 5px solid rgb(70, 70, 70);
  6.             overflow: hidden;
  7.             position: relative;
  8.         }
复制代码
border-bottom: 5px solid rgb(70, 70, 70); 给个灰色的眼底。
overflow:溢出隐藏。
position: relative; 相对定位。
3. 开始先定义血轮眼的基本样式:
  1. .zuo{
  2.             transform: translateX(-135px);
  3.             border-radius: 0 120px 0 120px;
  4.             box-shadow: inset 3px 2px 3px  rgba(17, 17, 17, 0.8);
  5.         }
复制代码
transform: translateX(-135px); 向左偏移,让两眼分开。
border-radius:给两个角设置弧度,形成眼睛形状。
bos-shadowL给眼角一点阴影。
4. 设置眼球宽高等:
  1. .zuo::after{
  2.             content: '';
  3.             position: absolute;
  4.             top: 50%;
  5.             left: 50%;
  6.             transform: translate(-50%,-50%);
  7.             width: 95px;
  8.             height: 95px;
  9.             border-radius: 50%;
  10.             border: 2px solid #000;
  11.             animation: colour 2s linear forwards;
  12.         }
  13.         @keyframes colour{
  14.             0%,30%{
  15.                 background-color: rgb(0, 0, 0);
  16.             }
  17.             100%{
  18.                  background-color: rgb(255, 4, 4);
  19.              }
  20.          }
复制代码
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. 设置眼球正中间的黑点,都是些定位大小啥的,然后设置动画然它慢慢变大:
  1. .zuoZong{
  2.             position: absolute;
  3.             top: 50%;
  4.             left: 50%;
  5.             transform: translate(-50%,-50%);
  6.             width: 0px;
  7.             height: 0px;
  8.             border-radius: 50%;
  9.             background-color: rgb(0, 0, 0);
  10.             z-index: 1;
  11.             animation: da 3s linear forwards;
  12.         }
  13.         @keyframes da{
  14.             100%{
  15.                 width: 15px;
  16.             height: 15px;
  17.             }
  18.         }
复制代码
6. 设置三勾玉所在的圈,设置动画让其显示与旋转:
  1. .zuoYu{
  2.             position: absolute;
  3.             top: -25px;
  4.             left: -25px;
  5.             bottom: -25px;
  6.             right: -25px;
  7.             border-radius: 50%;
  8.             border: 2px solid rgb(0, 0, 0);
  9.             animation: zhuan 2s linear 2s forwards;
  10.             opacity: 0;
  11.         }
  12.         @keyframes zhuan{
  13.             100%{
  14.                 opacity: 1;
  15.                 transform: rotate(720deg);
  16.             }
  17.         }
复制代码
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. 制作三勾玉,先做一个圆,再用双伪类制作一个圆弧,两者结合就是勾玉了:
  1. .zuoYu .yu{
  2.              position: absolute;
  3.              width: 15px;
  4.              height: 15px;
  5.              border-radius: 50%;
  6.              background-color: rgb(0, 0, 0);
  7.         }
  8.         .zuoYu .yu::after{
  9.             content: '';
  10.             position: absolute;
  11.             top: -6px;
  12.             left: -1px;
  13.             width: 6px;
  14.             height: 20px;
  15.             border-radius: 50%;
  16.             border-left: 6px solid rgb(0, 0, 0);
  17.         }
复制代码
border-radius: 50%;
border-left: 6px solid rgb(0, 0, 0);
先让伪类为圆,再只设置一条边框,圆弧形成,再定位在父元素上,形成勾玉。
8. 给勾玉设置动画,让其从最中间变大旋转到勾玉所在的圈:
  1. .zuoYu .yu:nth-child(1){
  2.             animation: yu1 2s ease-in 2s  forwards;
  3.         }
  4.         @keyframes yu1{
  5.             0%{
  6.                 opacity: 0;
  7.                 left: 50%;
  8.                 top: 50%;               
  9.                 transform:translate(-50%,-50%)  scale(0.1) ;
  10.             }
  11.             100%{
  12.                 left: 50%;
  13.                 top: -9%;
  14.                 transform: scale(1) rotate(80deg);  
  15.             }
  16.         }
复制代码
left: 50%;
top: 50%; 在最中间。
opacity:透明。
scale(0.1);缩小。
100%{…}到对应位置,同时变不透明和放大成正常大小。
9. 一样的,给其它两个勾玉动画:
  1. .zuoYu .yu:nth-child(2){
  2.             animation: yu2 2s ease-in 2s forwards;
  3.         }
  4.         @keyframes yu2{
  5.             0%{
  6.                 opacity: 0;
  7.                 left: 50%;
  8.                 top: 50%;
  9.                 transform: translate(-50%,-50%) scale(0.1) ;
  10.             }
  11.             100%{
  12.                 top: 60%;
  13.                 left: -9%;
  14.                 transform: scale(1) rotate(-60deg);  
  15.             }
  16.         }
  17.         .zuoYu .yu:nth-child(3){         
  18.             animation: yu3 2s ease-in 2s forwards;
  19.         }
  20.         @keyframes yu3{
  21.             0%{
  22.                 opacity: 0;
  23.                 right: 50%;
  24.                 top: 50%;
  25.                 transform: translate(-50%,-50%) scale(0.1);
  26.             }
  27.             100%{
  28.                 top: 60%;
  29.                 right: -9%;
  30.                 transform: scale(1) rotate(180deg);  
  31.             }
  32.         }
复制代码
10.给两个眼睛都设置一个白点,相当于反光效果吧,至此血轮眼做完了:
  1. .zuo::before,.you::before{
  2.             content: '';
  3.             position: absolute;
  4.             left: 38%;
  5.             top: 30%;
  6.             width: 12px;
  7.             height: 12px;
  8.             border-radius: 50%;
  9.             background-color: rgb(255, 255, 255);
  10.             z-index: 10;
  11.         }
复制代码
position: absolute;
left: 38%;
top: 30%; 定位相应的位置。
background-color: rgb(255, 255, 255); 白色。
z-index: 10; 设置为10,显示在最上层。
11.设置轮回眼基本css样式,跟血轮眼一样:
  1. .you{
  2.             transform: translateX(135px);
  3.             border-radius:  120px 0 120px 0;
  4.             box-shadow: inset -3px 2px 3px  rgba(17, 17, 17, 0.8);
  5.         }
复制代码
12.设置眼球宽高等:
  1. .you::after{
  2.             content: '';
  3.             position: absolute;
  4.             top: 50%;
  5.             left: 50%;
  6.             transform: translate(-50%,-50%);
  7.             width: 95px;
  8.             height: 95px;
  9.             border-radius: 50%;
  10.             border: 2px solid #000;
  11.             animation: youcolor 2s linear forwards;
  12.          }
  13.          @keyframes youcolor{
  14.             0%,30%{
  15.                 background-color: rgb(0, 0, 0);
  16.             }
  17.             100%{
  18.                  background-color: rgb(144, 130, 183);
  19.              }
  20.          }
复制代码
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. 设置眼球最中间的黑点,跟血轮眼也差不多:
  1. .dian{      
  2.              position: absolute;
  3.             top: 50%;
  4.             left: 50%;              
  5.             background-color: #000;
  6.             transform: translate(-50%,-50%);
  7.             border-radius: 50%;
  8.             z-index: 10;
  9.             animation: youda 3s linear forwards;
  10.          }
  11.          @keyframes youda{
  12.              0%{
  13.                 height: 0px;
  14.             width: 0px;
  15.              }
  16.              100%{
  17.                 height: 15px;
  18.             width: 15px;
  19.              }
  20.          }
复制代码
14. 设置轮回眼每个圈,同时设置动画让其变大:
  1. .youYu{
  2.             position: absolute;
  3.           top: 50%;
  4.           left: 50%;
  5.           transform: translate(-50%,-50%);
  6.        }
  7.        .quan{
  8.            position: absolute;
  9.            border-radius: 50%;
  10.            border: 2px solid #000;
  11.            z-index: calc(1 - var(--r));
  12.            animation: zhi 2s ease-out 2s forwards;
  13.        }
  14.        @keyframes zhi{
  15.            0%{
  16.             top: calc(var(--r) * 1px);
  17.            left: calc(var(--r) * 1px);
  18.            right: calc(var(--r) * 1px);
  19.            bottom: calc(var(--r) * 1px);
  20.            }
  21.            100%{
  22.             top: calc(var(--r) * -35px);
  23.            left: calc(var(--r) * -35px);
  24.            right: calc(var(--r) * -35px);
  25.            bottom: calc(var(--r) * -35px);
  26.                background-color: rgb(187, 177, 214);
  27.            }
  28.        }
复制代码
z-index: calc(1 - var(–r)); 计算,让最开始的圈显示在最上层。
animation:设置动画,让轮回圈慢慢变大,同时变成紫色。
完整代码:
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>Document</title>
  8.     <style>
  9.         *{
  10.             margin: 0;
  11.             padding: 0;
  12.             box-sizing: border-box;
  13.         }
  14.         body{
  15.             height: 100vh;
  16.             display: flex;
  17.             justify-content: center;
  18.             align-items: center;
  19.             background-color: #000;
  20.         }
  21.         .zuo , .you{
  22.             width: 250px;
  23.             height: 120px;
  24.             background-color: rgb(255, 255, 255);
  25.             border-bottom: 5px solid rgb(70, 70, 70);
  26.             overflow: hidden;
  27.             position: relative;
  28.         }
  29.         .zuo{
  30.             transform: translateX(-135px);
  31.             border-radius: 0 120px 0 120px;
  32.             box-shadow: inset 3px 2px 3px  rgba(17, 17, 17, 0.8);
  33.         }
  34.         .zuo::after{
  35.             content: '';
  36.             position: absolute;
  37.             top: 50%;
  38.             left: 50%;
  39.             transform: translate(-50%,-50%);
  40.             width: 95px;
  41.             height: 95px;
  42.             border-radius: 50%;
  43.             border: 2px solid #000;
  44.             animation: colour 2s linear forwards;
  45.         }
  46.         @keyframes colour{
  47.             0%,30%{
  48.                 background-color: rgb(0, 0, 0);
  49.             }
  50.             100%{
  51.                  background-color: rgb(255, 4, 4);
  52.              }
  53.          }
  54.         .zuoZong{
  55.             position: absolute;
  56.             top: 50%;
  57.             left: 50%;
  58.             transform: translate(-50%,-50%);
  59.             width: 0px;
  60.             height: 0px;
  61.             border-radius: 50%;
  62.             background-color: rgb(0, 0, 0);
  63.             z-index: 1;
  64.             animation: da 3s linear forwards;
  65.         }
  66.         @keyframes da{
  67.             100%{
  68.                 width: 15px;
  69.             height: 15px;
  70.             }
  71.         }
  72.         .zuoYu{
  73.             position: absolute;
  74.             top: -25px;
  75.             left: -25px;
  76.             bottom: -25px;
  77.             right: -25px;
  78.             border-radius: 50%;
  79.             border: 2px solid rgb(0, 0, 0);
  80.             animation: zhuan 2s linear 2s forwards;
  81.             opacity: 0;
  82.         }
  83.         @keyframes zhuan{
  84.             100%{
  85.                 opacity: 1;
  86.                 transform: rotate(720deg);
  87.             }
  88.         }
  89.         .zuoYu .yu{
  90.              position: absolute;
  91.              width: 15px;
  92.              height: 15px;
  93.              border-radius: 50%;
  94.              background-color: rgb(0, 0, 0);
  95.         }
  96.         .zuoYu .yu::after{
  97.             content: '';
  98.             position: absolute;
  99.             top: -6px;
  100.             left: -1px;
  101.             width: 6px;
  102.             height: 20px;
  103.             border-radius: 50%;
  104.             border-left: 6px solid rgb(0, 0, 0);
  105.         }
  106.         .zuoYu .yu:nth-child(1){
  107.             animation: yu1 2s ease-in 2s  forwards;
  108.         }
  109.         @keyframes yu1{
  110.             0%{
  111.                 opacity: 0;
  112.                 left: 50%;
  113.                 top: 50%;
  114.                 transform:translate(-50%,-50%)  scale(0.1) ;
  115.             }
  116.             100%{
  117.                 left: 50%;
  118.                 top: -9%;
  119.                 transform: scale(1) rotate(80deg);  
  120.             }
  121.         }      
  122.         .zuoYu .yu:nth-child(2){
  123.             animation: yu2 2s ease-in 2s forwards;
  124.         }
  125.         @keyframes yu2{
  126.             0%{
  127.                 opacity: 0;
  128.                 left: 50%;
  129.                 top: 50%;
  130.                 transform: translate(-50%,-50%) scale(0.1) ;
  131.             }
  132.             100%{
  133.                 top: 60%;
  134.                 left: -9%;
  135.                 transform: scale(1) rotate(-60deg);  
  136.             }
  137.         }
  138.         .zuoYu .yu:nth-child(3){         
  139.             animation: yu3 2s ease-in 2s forwards;
  140.         }
  141.         @keyframes yu3{
  142.             0%{
  143.                 opacity: 0;
  144.                 right: 50%;
  145.                 top: 50%;
  146.                 transform: translate(-50%,-50%) scale(0.1);
  147.             }
  148.             100%{
  149.                 top: 60%;
  150.                 right: -9%;
  151.                 transform: scale(1) rotate(180deg);  
  152.             }
  153.         }
  154.         .zuo::before,.you::before{
  155.             content: '';
  156.             position: absolute;
  157.             left: 38%;
  158.             top: 30%;
  159.             width: 12px;
  160.             height: 12px;
  161.             border-radius: 50%;
  162.             background-color: rgb(255, 255, 255);
  163.             z-index: 10;
  164.         }
  165.         .you{
  166.             transform: translateX(135px);
  167.             border-radius:  120px 0 120px 0;
  168.             box-shadow: inset -3px 2px 3px  rgba(17, 17, 17, 0.8);
  169. /*             filter: drop-shadow( 8px -5px 3px  rgb(216, 59, 59));
  170. */        }
  171.          .you::after{
  172.             content: '';
  173.             position: absolute;
  174.             top: 50%;
  175.             left: 50%;
  176.             transform: translate(-50%,-50%);
  177.             width: 95px;
  178.             height: 95px;
  179.             border-radius: 50%;
  180.             border: 2px solid #000;
  181.             animation: youcolor 2s linear forwards;
  182.          }
  183.          @keyframes youcolor{
  184.             0%,30%{
  185.                 background-color: rgb(0, 0, 0);
  186.             }
  187.             100%{
  188.                  background-color: rgb(144, 130, 183);
  189.              }
  190.          }
  191.          .dian{      
  192.              position: absolute;
  193.             top: 50%;
  194.             left: 50%;              
  195.             background-color: #000;
  196.             transform: translate(-50%,-50%);
  197.             border-radius: 50%;
  198.             z-index: 10;
  199.             animation: youda 3s linear forwards;
  200.          }
  201.          @keyframes youda{
  202.              0%{
  203.                 height: 0px;
  204.             width: 0px;
  205.              }
  206.              100%{
  207.                 height: 15px;
  208.             width: 15px;
  209.              }
  210.          }
  211.          .youYu{
  212.             position: absolute;
  213.           top: 50%;
  214.           left: 50%;
  215.           transform: translate(-50%,-50%);
  216.        }
  217.        .quan{
  218.            position: absolute;
  219.            border-radius: 50%;
  220.            border: 2px solid #000;
  221.            z-index: calc(1 - var(--r));
  222.            animation: zhi 2s ease-out 2s forwards;
  223.        }
  224.        @keyframes zhi{
  225.            0%{
  226.             top: calc(var(--r) * 1px);
  227.            left: calc(var(--r) * 1px);
  228.            right: calc(var(--r) * 1px);
  229.            bottom: calc(var(--r) * 1px);
  230.            }
  231.            100%{
  232.             top: calc(var(--r) * -35px);
  233.            left: calc(var(--r) * -35px);
  234.            right: calc(var(--r) * -35px);
  235.            bottom: calc(var(--r) * -35px);
  236.                background-color: rgb(187, 177, 214);
  237.            }
  238.        }
  239.     </style>
  240. </head>
  241. <body>
  242.     <!-- 血轮眼 -->
  243.     <div class="zuo">
  244.         <!-- 眼睛最中间那个黑点 -->
  245.         <div class="zuoZong">
  246.             <!-- 三勾玉所在的圈 -->
  247.             <div class="zuoYu">
  248.                 <!-- 三个勾玉 -->
  249.                 <span class="yu"></span>
  250.                 <span class="yu"></span>
  251.                 <span class="yu"></span>
  252.             </div>
  253.         </div>
  254.     </div>
  255.     <!-- 轮回眼 -->
  256.     <div class="you">
  257.         <!-- 眼睛最中间那个黑点 -->
  258.         <div class="dian"></div>
  259.              <!-- 3个轮回圈 -->
  260.             <div class="youYu">                        
  261.                 <span class="quan" style="--r:2;"></span>
  262.                 <span class="quan" style="--r:3;"></span>
  263.                 <span class="quan" style="--r:4;"></span>
  264.             </div>      
  265.     </div>
  266. </body>
  267. </html>
复制代码
到此这篇关于html+css实现血轮眼轮回眼特效 的文章就介绍到这了,更多相关html血轮眼轮回眼特效 内容请搜索中国红客联盟以前的文章或继续浏览下面的相关文章,希望大家以后多多支持中国红客联盟!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行