How to create a pulsing glow ring animation in CSS?

后端 未结 1 878
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 19:31

I like the way this website made their rings glow and pulse out and would like to know how they did it.

I can make something similar but I\'m not very good.

相关标签:
1条回答
  • 2020-12-31 20:01

    The threads linked in comments are helpful but I don't think this is an exact duplicate because this one is slightly more complex due to the need for multiple rings.

    We can create this effect by animating transform: scale() and opacity of the elements. Here, we need more than 1 element because in the linked website we can see atleast 3 rings at any given point of time (one which is fading-in, one which is at its peak, one which is fading-out). By adding the same animation to two pseudo-elements, an inner element (the span) and by delaying the animation on two of them we can achieve the required animation effect.

    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;
    }
    <div>
      <span></span>
    </div>

    0 讨论(0)
提交回复
热议问题