使用CSS进行环形动画

Ric*_*tos 3 html css css3 flexbox css-animations

我想要一个从的中心开始div而不是从的左上角开始的扩展半径div

想象一下,按钮有一个向外跳动的轮廓。该脉动轮廓应该从中间开始div,然后向外走。

在此处查看示例:https : //jsbin.com/dinehoqaro/edit?html,css,output

您可以看到扩展从左上方开始。

.circle {
  background-color: white;
  border: 1px solid red;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: pulse 1s infinte;
  -webkit-animation: pulse 1.2s infinite;
}
button {
  background-color: green;
  border: none;
  border-radius: 50%;
  width: 50px;
  height: 50px;
}
@-webkit-keyframes pulse {
  from {
    width: 50px;
    height: 50px;
  }
  to {
    width: 100px height: 100px;
  }
}
@keyframes pulse {
  from {
    width: 50px;
    height: 50px;
  }
  to {
    width: 100px;
    height: 100px;
  }
}
Run Code Online (Sandbox Code Playgroud)
<div class="circle"><button>click here</button></div>
Run Code Online (Sandbox Code Playgroud)

Mic*_*l_B 5

这是使用CSS flexboxtransformpseudo-elements的一般解决方案。

body {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: lightyellow;
  height: 100vh;
  margin: 0;
}
#container {
  display: flex;
  align-items: center;
  justify-content: center;
}
.sphere {
  display: flex;
  background: lightblue;
  border-radius: 300px;
  height: 100px;
  width: 100px;
}
#container::after {
  display: flex;
  background: lightpink;
  border-radius: 300px;
  height: 250px;
  width: 250px;
  animation: pulsate 2.5s ease-out;
  animation-iteration-count: infinite;
  opacity: 0.0;
  content: "";
  z-index: -1;
  margin: auto;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}
@keyframes pulsate {
  0% {
    transform: scale(0.1, 0.1);
    opacity: 0.0;
  }
  50% {
    opacity: 1.0;
  }
  100% {
    transform: scale(1.2, 1.2);
    opacity: 0.0;
  }
}
Run Code Online (Sandbox Code Playgroud)
<div id="container">
  <div class="sphere"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

jsFiddle

另请参阅@harry的出色解决方案:如何在CSS中创建脉动的发光环动画?