如何在CSS中创建脉冲发光环动画?

8 css visual-web-developer css-animations

我喜欢这个网站让他们的戒指发光和脉冲的方式,并想知道他们是如何做到的.

我可以做类似的东西,但我不是很好.

所以这就是我能够弄清楚的但它似乎不起作用.

CSS:

glowycircleouter.blue .glow4 {
  box-shadow: 0 0 25px #287ec6;
}
.glowycircleouter .glow4 {
  -webkit-animation: glowyglow 3s 2250ms infinite;
  -moz-animation: glowyglow 3s 2250ms infinite;
  -ms-animation: glowyglow 3s 2250ms infinite;
  -o-animation: glowyglow 3s 2250ms infinite;
  animation: glowyglow 3s 2250ms infinite;
  animation-name: glowyglow;
  animation-duration: 3s;
  animation-timing-function: initial;
  animation-delay: 2250ms;
  animation-iteration-count: infinite;
  animation-direction: initial;
  animation-fill-mode: initial;
  animation-play-state: initial;
}
.glowycircleouter .glow4 {
  opacity: 0;
  display: block;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 200%;
  height: 200%;
  -webkit-transform: translate(-50%, -50%);
  -moz-transform: translate(-50%, -50%);
  -o-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  -webkit-border-radius: 50%;
  -moz-border-radius: 50%;
  border-radius: 50%;
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<span class="glow4"></span>
Run Code Online (Sandbox Code Playgroud)

Har*_*rry 21

注释中链接的线程很有帮助,但我不认为这是完全重复的,因为由于需要多个环,这个稍微复杂一些.

我们可以通过动画transform: scale()opacity元素来创建这种效果.在这里,我们需要超过1个元素,因为在链接的网站中我们可以在任何给定的时间点看到至少3个环(一个是淡入的,一个是在其峰值,一个是淡出的).通过将相同的动画添加到两个伪元素,一个内部元素(span),并通过在其中两个上延迟动画,我们可以实现所需的动画效果.

div {
  position: relative;
  height: 100px;
  width: 100px;
  border-radius: 50%;
  margin: 50px;
  border: 2px solid white;
}
div:before,
div:after, span {
  position: absolute;
  content: '';
  height: 100%;
  width: 100%;
  top: 0%;
  left: 0%;
  border-radius: 50%;
  box-shadow: 0 0 15px #287ec6;
  animation: glow-grow 2s ease-out infinite;
}
div:after {
  animation-delay: .66s;
}
span{
  animation-delay: 1.33s;
  }
@keyframes glow-grow {
  0% {
    opacity: 0;
    transform: scale(1);
  }
  80% {
    opacity: 1;
  }
  100% {
    transform: scale(2);
    opacity: 0;
  }
}
body {
  background: black;
}
Run Code Online (Sandbox Code Playgroud)
<div>
  <span></span>
</div>
Run Code Online (Sandbox Code Playgroud)