CSS3动画——飞行的小精灵

打印 上一主题 下一主题

主题 566|帖子 566|积分 1698

CSS3动画——飞行的小精灵

今天的这段代码通过多层结构、渐变色、圆角、多种动画效果以及细节处理,成功地创造了一个布满活力和趣味性的飞行小精灵动画效果。
效果如下:

     飞行的小精灵
  
源代码如下:
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.   <title>飞行的小精灵</title>
  7.   <style>
  8.     * {
  9.       padding: 0;
  10.       margin: 0;
  11.     }
  12.     body {
  13.       background-color: rgb(15, 17, 29);
  14.       width: 100%;
  15.       overflow: hidden;
  16.     }
  17.     div {
  18.       width: 150px;
  19.       height: 150px;
  20.     }
  21.     ul {
  22.       display: block;
  23.       width: 100%;
  24.       height: 100%;
  25.       font-size: 0px;
  26.     }
  27.     /* 最外层容器 */
  28.     .container {
  29.       translate: 0 50%;
  30.       margin: 0 auto;
  31.       width: 100%;
  32.       height: 300px;
  33.     }
  34.     .main-container {
  35.       position: relative;
  36.       width: 100%;
  37.       height: 100%;
  38.     }
  39.     /* 外层紫色盒子 */
  40.     .first {
  41.       margin: 0 auto;
  42.       translate: 0 50%;
  43.       /* border: 1px solid #fff; */
  44.       box-shadow: 5px 5px 10px 5px rgba(80, 72, 160, 0.9) 30%, rgb(126, 117, 224, 0.5);
  45.     }
  46.     /* 紫色拖尾 */
  47.     .first ul li {
  48.       width: 100%;
  49.       height: 25%;
  50.       border-top-right-radius: 15px;
  51.       border-bottom-right-radius: 15px;
  52.       animation: first .7s ease-in-out infinite alternate;
  53.       background-image: linear-gradient(to right, rgba(80, 72, 160, 0.9) 30%, rgb(126, 117, 224, 0.5));
  54.       mask-image: linear-gradient(to right, rgba(80, 72, 160, 0.9) 70%, transparent);
  55.     }
  56.     .first ul li:nth-child(1) {
  57.       animation-delay: .3s;
  58.     }
  59.     .first ul li:nth-child(2) {
  60.       animation: first 2s 0.4s ease-out infinite alternate;
  61.     }
  62.     .first ul li:nth-child(3) {
  63.       animation: first 1.5s 0.3s ease-out infinite alternate;
  64.     }
  65.     .first ul li:nth-child(4) {
  66.       animation-delay: .5s;
  67.     }
  68.     @keyframes first {
  69.       0% {
  70.         width: 60%;
  71.         opacity: 1;
  72.       }
  73.       100% {
  74.         width: 140%;
  75.       }
  76.     }
  77.     .first::before {
  78.       content: '';
  79.       position: absolute;
  80.       left: -50%;
  81.       width: 50%;
  82.       height: 100%;
  83.       border-top-left-radius: 75px;
  84.       border-bottom-left-radius: 75px;
  85.       background-color: rgba(80, 72, 160, 0.9);
  86.       box-shadow: -2px 0 5px rgba(80, 72, 160, 0.7);
  87.     }
  88.     /* 第二层 */
  89.     .second {
  90.       margin: 0 auto;
  91.       translate: 0 -50%;
  92.       height: 130px;
  93.     }
  94.     .second ul li {
  95.       height: 25%;
  96.       width: 100%;
  97.       background-color: rgba(133, 237, 232, 0.6);
  98.       border-top-right-radius: 15px;
  99.       border-bottom-right-radius: 15px;
  100.       animation: second .6s ease-out infinite alternate;
  101.       mask-image: linear-gradient(to right, #85EDE8 50%, transparent);
  102.     }
  103.     .second ul li:last-child {
  104.       translate: 0 200%;
  105.       animation-delay: 0.4s;
  106.     }
  107.     @keyframes second {
  108.       0% {
  109.         width: 80%;
  110.       }
  111.       100% {
  112.         width: 130%;
  113.       }
  114.     }
  115.     .second::before {
  116.       content: '';
  117.       position: absolute;
  118.       left: -65px;
  119.       width: 50%;
  120.       height: 100%;
  121.       border-top-left-radius: 75px;
  122.       border-bottom-left-radius: 75px;
  123.       background: #85EDE8;
  124.       box-shadow: -2px 0 5px rgba(133, 237, 232, 0.7);
  125.     }
  126.     /* 第三层 */
  127.     .third {
  128.       position: relative;
  129.       margin: 0 auto;
  130.       translate: 0 -205px;
  131.     }
  132.     .third ul li {
  133.       width: 100%;
  134.       height: 10%;
  135.       border-top-right-radius: 7.5px;
  136.       border-bottom-right-radius: 7.5px;
  137.       background-color: rgb(133, 237, 232);
  138.       animation: third 1s infinite alternate;
  139.       box-shadow: 0 0 5px rgba(133, 237, 232, 0.5);
  140.     }
  141.     .third .top {
  142.       position: absolute;
  143.       top: 10px;
  144.       left: 0;
  145.     }
  146.     .third .bottom {
  147.       position: absolute;
  148.       bottom: 10px;
  149.       left: 0;
  150.     }
  151.     .third ul li:nth-child(1) {
  152.       animation-delay: 0.7s;
  153.     }
  154.     .third ul li:nth-child(2) {
  155.       width: 25px;
  156.       height: 15px;
  157.       border-radius: 50px;
  158.       animation: third-1 1.5s ease-out infinite;
  159.     }
  160.     .third ul li:nth-child(4) {
  161.       width: 15px;
  162.       border-radius: 50px;
  163.       animation: third-1 1.5s ease-out infinite;
  164.     }
  165.     .third ul li:nth-child(3) {
  166.       width: 50px;
  167.       border-radius: 50px;
  168.       animation: third-2 1s 0.1s ease-out infinite;
  169.     }
  170.     .third ul li:nth-child(5) {
  171.       width: 60px;
  172.       border-radius: 70px;
  173.       animation: third-2 1s 0.4s ease-out infinite;
  174.     }
  175.     @keyframes third {
  176.       0% {
  177.         width: 55%;
  178.       }
  179.       100% {
  180.         width: 85%;
  181.       }
  182.     }
  183.     @keyframes third-1 {
  184.       0% {
  185.         left: 35px;
  186.       }
  187.       80% {
  188.         cpacity: 0.7;
  189.       }
  190.       100% {
  191.         left: 200px;
  192.         opacity: 0;
  193.       }
  194.     }
  195.     @keyframes third-2 {
  196.       0% {
  197.         left: 35px;
  198.       }
  199.       80% {
  200.         cpacity: 0.7;
  201.       }
  202.       100% {
  203.         left: 200px;
  204.         opacity: 0;
  205.       }
  206.     }
  207.     .third::before {
  208.       content: '';
  209.       position: absolute;
  210.       top: 25px;
  211.       left: -50px;
  212.       width: 70px;
  213.       height: 100px;
  214.       border-top-left-radius: 65px;
  215.       border-bottom-left-radius: 65px;
  216.       background-color: #fff;
  217.     }
  218.     /* 面部的图案,待会儿取消注释*/
  219.     .fourth {
  220.       position: relative;
  221.       width: 100px;
  222.       height: 100px;
  223.       background-color: transparent;
  224.       margin: 0 auto;
  225.       /* 因为前面的div盒子撑起来了 */
  226.       translate: -25px -330%;
  227.       background-color: #fff;
  228.     }
  229.     .fourth .eyes {
  230.       position: absolute;
  231.       top: 40px;
  232.       left: 0px;
  233.       width: 10px;
  234.       height: 10px;
  235.       border-radius: 50%;
  236.       background-color: #000;
  237.     }
  238.     .eyes::after {
  239.       content: "";
  240.       position: absolute;
  241.       top: 0;
  242.       left: 30px;
  243.       width: 10px;
  244.       height: 10px;
  245.       border-radius: 50%;
  246.       background-color: #000;
  247.     }
  248.     .checks {
  249.       position: absolute;
  250.       top: 52px;
  251.       left: -10px;
  252.       width: 10px;
  253.       height: 10px;
  254.       border-radius: 50%;
  255.       background-color: rgb(133, 237, 232);
  256.     }
  257.     .checks::after {
  258.       content: "";
  259.       position: absolute;
  260.       top: 0;
  261.       left: 50px;
  262.       width: 10px;
  263.       height: 10px;
  264.       border-radius: 50%;
  265.       background-color: rgb(133, 237, 232);
  266.     }
  267.     .smile {
  268.       position: absolute;
  269.       top: 53px;
  270.       left: 8px;
  271.       width: 20px;
  272.       height: 10px;
  273.       border: 3px solid #000;
  274.       border-bottom-left-radius: 90px;
  275.       border-bottom-right-radius: 90px;
  276.     }
  277.     /* 嘴型的设置 */
  278.     .smile::after {
  279.       content: "";
  280.       position: absolute;
  281.       top: -5px;
  282.       left: -5px;
  283.       width: 30px;
  284.       height: 7px;
  285.       background-color: #fff;
  286.     }
  287.     /* 设置动画条 */
  288.     .fourth ul li {
  289.       position: absolute;
  290.       width: 100%;
  291.       height: 15px;
  292.       background-color: #fff;
  293.       left: 1px;
  294.     }
  295.     .fourth ul .odd {
  296.       border-top-right-radius: 50px;
  297.       border-bottom-right-radius: 50px;
  298.     }
  299.     .fourth ul .even {
  300.       background: radial-gradient(circle at 100% 50%, transparent 15px, #fff 18px);
  301.     }
  302.     .fourth ul li:nth-child(1) {
  303.       top: 0px;
  304.       animation: fourth-1 1s ease-in-out infinite alternate;
  305.     }
  306.     .fourth ul li:nth-child(2) {
  307.       top: 12px;
  308.       height: 17px;
  309.       animation: fourth-2 1s 0.2s ease-in-out infinite alternate;
  310.       filter: blur(1px);
  311.     }
  312.     .fourth ul li:nth-child(3) {
  313.       top: 27px;
  314.       animation: fourth-3 1s 0.4s ease-in-out infinite alternate;
  315.     }
  316.     .fourth ul li:nth-child(4) {
  317.       top: 41px;
  318.       height: 17px;
  319.       animation: fourth-4 1s 0.6s ease-in-out infinite alternate;
  320.     }
  321.     .fourth ul li:nth-child(5) {
  322.       bottom: 28px;
  323.       animation: fourth-5 1s 0.6s ease-in-out infinite alternate;
  324.     }
  325.     .fourth ul li:nth-child(6) {
  326.       bottom: 14px;
  327.       animation: fourth-6 01s 0.6s ease-in-out infinite alternate;
  328.     }
  329.     .fourth ul li:nth-child(7) {
  330.       bottom: 0px;
  331.       animation: fourth-7 1s 0.6s ease-in-out infinite alternate;
  332.     }
  333.     @keyframes fourth-1 {
  334.       0% {
  335.         width: 120%;
  336.       }
  337.       100% {
  338.         width: 140%;
  339.       }
  340.     }
  341.     @keyframes fourth-2 {
  342.       0% {
  343.         width: 120%
  344.       }
  345.       100% {
  346.         width: 125%;
  347.       }
  348.     }
  349.     @keyframes fourth-3 {
  350.       0% {
  351.         width: 130%;
  352.       }
  353.       100% {
  354.         width: 150%;
  355.       }
  356.     }
  357.     @keyframes fourth-4 {
  358.       0% {
  359.         width: 125%;
  360.       }
  361.       100% {
  362.         width: 140%;
  363.       }
  364.     }
  365.     @keyframes fourth-5 {
  366.       0% {
  367.         width: 120%;
  368.       }
  369.       100% {
  370.         width: 150%;
  371.       }
  372.     }
  373.     @keyframes fourth-6 {
  374.       0% {
  375.         width: 120%;
  376.       }
  377.       100% {
  378.         width: 130%;
  379.       }
  380.     }
  381.     @keyframes fourth-7 {
  382.       0% {
  383.         width: 130%;
  384.       }
  385.       100% {
  386.         width: 155%;
  387.       }
  388.     }
  389.     @keyframes fourth-8 {
  390.       0% {
  391.         width: 155%;
  392.       }
  393.       100% {
  394.         width: 165%;
  395.       }
  396.     }
  397.   </style>
  398. </head>
  399. <body>
  400.   <div class="container">
  401.     <div class="main-container">
  402.       <!-- 外层紫色 -->
  403.       <div class="first">
  404.         <ul>
  405.           <li></li>
  406.           <li></li>
  407.           <li></li>
  408.           <li></li>
  409.         </ul>
  410.       </div>
  411.       <!-- 第二层浅蓝 -->
  412.       <div class="second">
  413.         <ul>
  414.           <li></li>
  415.           <li></li>
  416.         </ul>
  417.       </div>
  418.       <!-- 第三层稍微深的蓝色 -->
  419.       <div class="third">
  420.         <ul>
  421.           <li class="top"></li>
  422.           <li class="top"></li>
  423.           <li class="top"></li>
  424.           <li class="bottom"></li>
  425.           <li class="bottom"></li>
  426.           <li class="bottom"></li>
  427.         </ul>
  428.       </div>
  429.       <!-- 内层图案 -->
  430.       <div class="fourth">
  431.         <ul>
  432.           <li class="odd"></li>
  433.           <li class="even"></li>
  434.           <li class="odd"></li>
  435.           <li class="even"></li>
  436.           <li class="odd"></li>
  437.           <li class="even"></li>
  438.           <li class="odd"></li>
  439.           <li class="even"></li>
  440.         </ul>
  441.         <!-- 面部图像 -->
  442.         <span class="eyes"></span>
  443.         <span class="checks"></span>
  444.         <span class="smile"></span>
  445.       </div>
  446.     </div>
  447.     <div class=" flying-starts"></div>
  448.   </div>
  449. </body>
  450. </html>
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

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

本版积分规则

乌市泽哥

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表