纯CSS实现心形加载动画(附源码)

 4241

本篇文章给大家介绍一下纯CSS实现心形加载动画的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。


纯CSS实现心形加载动画(附源码)


废话不多说上代码,代码很简答,研究一下就明白了,有不明白的可以问我。

  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <meta charset="utf-8">
  5.     <title></title>
  6.     <style type="text/css">
  7.       .heart-loading {
  8.         margin-top: 120px;
  9.         width: 200px;
  10.         height: 200px;
  11.       }
  12.   
  13.       ul {
  14.         list-style: none;
  15.         display: flex;
  16.         justify-content: space-between;
  17.         width: 150px;
  18.         height: 10px;
  19.         /* 做心形和条形想法是一样的,但是每条高度是不一样的 */
  20.       }
  21.       li {
  22.         --count: 9;
  23.         --rgb: calc(var(--index) / var(--count) * .5turn);
  24.         /* 不能把这个延时设置的太慢.太慢就看不出来是心形了,同时调整延时和动画时长即可 */
  25.         --time: calc((var(--index) - 1) * 150ms);
  26.         border-radius: 5px;
  27.         width: 10px;
  28.         height: 10px;
  29.         background-color: #003BB3;
  30.         /* 利用fiter函数可以让颜色渐变会非常漂亮 */
  31.         filter: hue-rotate(var(--rgb));
  32.         /* 下边这个是动画时长 */
  33.         animation-duration: 2.5s;
  34.         animation-delay: var(--time);
  35.         animation-iteration-count: infinite;
  36.       }
  37.       .line-1,
  38.       .line-9 {
  39.         animation-name: line-move-1;
  40.       }
  41.       .line-2,
  42.       .line-8 {
  43.         animation-name: line-move-2;
  44.       }
  45.       .line-3,
  46.       .line-7 {
  47.         animation-name: line-move-3;
  48.       }
  49.       .line-4,
  50.       .line-6 {
  51.         animation-name: line-move-4;
  52.       }
  53.       .line-5 {
  54.         animation-name: line-move-5;
  55.       }
  56.       /* 对称的动画要相同高度,这样看出心形了 */
  57.       @keyframes line-move-1 {
  58.   
  59.         0%,
  60.         10%,
  61.         90%,
  62.         100% {
  63.           height: 10px;
  64.         }
  65.   
  66.         45%,
  67.         55% {
  68.           height: 30px;
  69.           transform: translate3d(0, -15px, 0);
  70.         }
  71.       }
  72.   
  73.       @keyframes line-move-2 {
  74.   
  75.         0%,
  76.         10%,
  77.         90%,
  78.         100% {
  79.           height: 10px;
  80.         }
  81.   
  82.         45%,
  83.         55% {
  84.           height: 60px;
  85.           transform: translate3d(0, -30px, 0);
  86.         }
  87.       }
  88.   
  89.       @keyframes line-move-3 {
  90.   
  91.         0%,
  92.         10%,
  93.         90%,
  94.         100% {
  95.           height: 10px;
  96.         }
  97.   
  98.         45%,
  99.         55% {
  100.           height: 80px;
  101.           transform: translate3d(0, -40px, 0);
  102.         }
  103.       }
  104.   
  105.       @keyframes line-move-4 {
  106.   
  107.         0%,
  108.         10%,
  109.         90%,
  110.         100% {
  111.           height: 10px;
  112.         }
  113.   
  114.         45%,
  115.         55% {
  116.           height: 90px;
  117.           transform: translate3d(0, -30px, 0);
  118.         }
  119.       }
  120.   
  121.       @keyframes line-move-5 {
  122.   
  123.         0%,
  124.         10%,
  125.         90%,
  126.         100% {
  127.           height: 10px;
  128.         }
  129.   
  130.         45%,
  131.         55% {
  132.           height: 90px;
  133.           transform: translate3d(0, -20px, 0);
  134.         }
  135.       }
  136.     </style>
  137.   </head>
  138.   <body>
  139.     <div class="heart-loading">
  140.       <ul>
  141.         <li class="line-1" style="--index: 1"></li>
  142.         <li class="line-2" style="--index: 2"></li>
  143.         <li class="line-3" style="--index: 3"></li>
  144.         <li class="line-4" style="--index: 4"></li>
  145.         <li class="line-5" style="--index: 5"></li>
  146.         <li class="line-6" style="--index: 6"></li>
  147.         <li class="line-7" style="--index: 7"></li>
  148.         <li class="line-8" style="--index: 8"></li>
  149.         <li class="line-9" style="--index: 9"></li>
  150.       </ul>
  151.     </div>
  152.   </body>
  153. </html>


纯CSS实现心形加载动画(附源码)

TAG标签:
本文网址:https://www.zztuku.com/index.php/detail-8874.html
站长图库 - 纯CSS实现心形加载动画(附源码)
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐

    免费商用字体-小可奶酪体