跳至主要內容

四叶草加载动画

望间代码HTML&CSS加载动画动画大约 2 分钟

CSS 世界之四叶草加载动画

效果展示

<div class="container">
  <div class="clover-loading">
    <span class="leaf"></span>
    <span class="leaf"></span>
    <span class="leaf"></span>
    <span class="leaf"></span>
  </div>
</div>
.container {
  position: relative;
  height: 90px;
  width: 100%;
  display: flex;
  justify-content: center;
}
@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;
  }
}

实现思路

通过使用nth-of-type选择器,可以为每个叶子指定边框半径和背景颜色,形成四叶草,再通过旋转和缩放实现加载动画。

上次编辑于:
贡献者: ViewRoom