發光漸層光環 - CSS 動畫

運用 CSS 濾鏡(filter)製作出光暈效果,並加上 CSS 動畫。

Glowing Gradient Loader Ring Animation Effects | CSS Animation Tutorial

Step 1

布局

<div class="loader">
  <span></span>
  <span></span>
  <span></span>
  <span></span>
</div>
html,body {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-color: #111111;
}

Step 2

繪製主體

.loader {
  position: relative;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: linear-gradient(#40E0D0, #FF8C00, #FF0080);
  animation: animate 3s linear infinite;
}

Step 3

設定光暈效果

.loader span {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: linear-gradient(#40E0D0, #FF8C00, #FF0080);;
  animation: animate 3s linear infinite;
}
.loader span:nth-child(1) {
  filter: blur(5px);
}
.loader span:nth-child(2) {
  filter: blur(10px);
}
.loader span:nth-child(3) {
  filter: blur(25px);
}
.loader span:nth-child(4) {
  filter: blur(50px);
}

Step 4

遮色製作圈環

.loader:after {
  content: '';
  position: absolute;
  top: 40px;
  left: 40px;
  right: 40px;
  bottom: 40px;
  border-radius: 50%;
  background: #111111;
}

Step 5

動畫

@keyframes animate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

codepen

發光漸層光環 - CSS動畫
TOP