CSS 世界之四叶草加载动画
效果展示
实现思路
通过使用nth-of-type
选择器,可以为每个叶子指定边框半径和背景颜色,形成四叶草
再通过旋转和缩放实现加载动画
实现代码
1 2 3 4 5 6
| <div class="clover-loading"> <span class="leaf"></span> <span class="leaf"></span> <span class="leaf"></span> <span class="leaf"></span> </div>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
| <style> @keyframes cloverLoading{ 0%{ transform: scale(1) rotate(0); } 20%{ transform: scale(1) rotate(72deg); } 40%{ transform: scale(0.5) rotate(144deg); } 60%{ transform: scale(0.5) rotate(216deg); } 80%{ transform: scale(1) rotate(288deg); } 100%{ transform: scale(1) rotate(360deg); } } .clover-loading { width: 90px; height: 90px; display: flex; flex-wrap: wrap; justify-content: space-between; align-content: space-between; animation: cloverLoading 3s linear infinite; } .leaf{ width: 40px; height: 40px; display: block; border-radius: 20px 20px 20px 20px; box-sizing: border-box; } .leaf:nth-of-type(1){ background-color: #50DE68; animation: leaf-1 3s linear infinite; } .leaf:nth-of-type(2){ background-color: #3DC453; animation: leaf-2 3s linear infinite; } .leaf:nth-of-type(3){ background-color: #14BE71; animation: leaf-3 3s linear infinite; } .leaf:nth-of-type(4){ background-color: #78DE35; animation: leaf-4 3s linear infinite; } @keyframes leaf-1{ 0%{ border-radius: 20px 20px 20px 20px 20px; } 20%{ border-radius: 20px 20px 20px 20px; } 40%{ border-radius: 20px 20px 0 20px; } 60%{ border-radius: 20px 20px 0 20px; } 80%{ border-radius: 20px 20px 20px 20px 20px; } 100%{ border-radius: 20px 20px 20px 20px 20px; } } @keyframes leaf-2{ 0%{ border-radius: 20px 20px 20px 20px 20px; } 20%{ border-radius: 20px 20px 20px 20px; } 40%{ border-radius: 20px 20px 20px 0; } 60%{ border-radius: 20px 20px 20px 0; } 80%{ border-radius: 20px 20px 20px 20px 20px; } 100%{ border-radius: 20px 20px 20px 20px 20px; } } @keyframes leaf-3{ 0%{ border-radius: 20px 20px 20px 20px 20px; } 20%{ border-radius: 20px 20px 20px 20px; } 40%{ border-radius: 20px 0 20px 20px; } 60%{ border-radius: 20px 0 20px 20px; } 80%{ border-radius: 20px 20px 20px 20px 20px; } 100%{ border-radius: 20px 20px 20px 20px 20px; } } @keyframes leaf-4{ 0%{ border-radius: 20px 20px 20px 20px 20px; } 20%{ border-radius: 20px 20px 20px 20px; } 40%{ border-radius: 0 20px 20px 20px; } 60%{ border-radius: 0 20px 20px 20px; } 80%{ border-radius: 20px 20px 20px 20px 20px; } 100%{ border-radius: 20px 20px 20px 20px 20px; } } </style>
|