【问题标题】:Ripple animation showing circle one after another涟漪动画依次显示圆圈
【发布时间】:2021-12-10 16:45:01
【问题描述】:

您好,我想为我的徽标添加这种效果

但不知怎的,我被困住了,你能帮帮我吗?我希望圆圈一个接一个地显示,但只有在显示第四个圆圈时,效果才能结束。对不起我的英语不好。请帮忙

html,
body {
  color: #2E4453;
  font-size: 100%;
  font-family: 'Open Sans', Helvetica, Arial, sans-serif;
  font-weight: 400;
  background-color: #D1C4E9;
}

.open-dev-radar {
  position: relative;
  width: 100%;
  padding-top: 100%;
}

.open-dev-badge {
  position: absolute;
  left: 50%;
  top: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  width: 90px;
  height: 90px;
  /* padding: 15px; */
  border-radius: 50%;
  background-color: #fff;
  box-shadow: 1px 2px 7px rgba(0, 0, 0, 0.34);
}

.gt-dev {
  position: absolute;
  left: 50%;
  top: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

.gt-dev:after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  -webkit-transform: scale(0);
  -ms-transform: scale(0);
  transform: scale(0);
  border-radius: 50%;
  border: solid 1px rgba(103, 58, 182, 0.74);
  background-image: -webkit-radial-gradient(circle farthest-corner, rgba(103, 58, 182, 0) 52%, rgba(103, 58, 182, 0.62) 100%);
  background-image: radial-gradient( circle farthest-corner, rgba(103, 58, 182, 0) 52%, rgba(103, 58, 182, 0.62) 100%);
  -webkit-animation-duration: 9s;
  animation-duration: 9s;
  -webkit-animation-name: pulse;
  animation-name: pulse;
  -webkit-animation-iteration-count: infinite;
  animation-iteration-count: infinite;
  opacity: 0;
  filter: alpha(opacity=0);
}

.gt-dev:nth-child(4) {
  width: 120px;
  height: 120px;
}

.gt-dev:nth-child(3) {
  width: 190px;
  height: 190px;
}

.gt-dev:nth-child(3):after {
  -webkit-animation-delay: 0.2s;
  animation-delay: 0.2s;
}

.gt-dev:nth-child(2) {
  width: 270px;
  height: 270px;
}

.gt-dev:nth-child(2):after {
  -webkit-animation-delay: 0.4s;
  animation-delay: 0.4s;
}

.gt-dev:nth-child(1) {
  width: 370px;
  height: 370px;
}

.gt-dev:nth-child(1):after {
  -webkit-animation-delay: 0.6s;
  animation-delay: 0.6s;
}

@-webkit-keyframes pulse {
  0% {
    -webkit-transform: scale(0);
    transform: scale(0);
    opacity: 0;
    filter: alpha(opacity=0);
  }
  90% {
    -webkit-transform: scale(1);
    transform: scale(1);
    opacity: 1;
    filter: alpha(opacity=100);
  }
  100% {
    -webkit-transform: scale(1.1);
    transform: scale(1.1);
    opacity: 0;
    filter: alpha(opacity=0);
  }
}

@keyframes pulse {
  0% {
    -webkit-transform: scale(0);
    transform: scale(0);
    opacity: 0;
    filter: alpha(opacity=0);
  }
  90% {
    -webkit-transform: scale(1);
    transform: scale(1);
    opacity: 1;
    filter: alpha(opacity=50);
  }
  100% {
    -webkit-transform: scale(1.1);
    transform: scale(1.1);
    opacity: 0;
    filter: alpha(opacity=100);
  }
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Ripple Animation</title>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <div class="gt-dev"></div>
  <div class="gt-dev"></div>
  <div class="gt-dev"></div>
  <div class="gt-dev"></div>
  <div class="open-dev-badge"><img src="Loader.svg"></div>

</body>

</html>

【问题讨论】:

  • 请向我们展示您目前拥有的代码。如果我们能自己看到问题,这将对我们有所帮助,因此包括一个有效的 sn-p。见stackoverflow.com/help/minimal-reproducible-example
  • 是的,但我想显示第一个圆圈停止效果,这样圆圈不会消失或消失然后显示第二个停止效果显示第三个圆圈停止效果,然后当显示第四个圆圈时所有圆圈然后消失或消失。

标签: css css-animations ripple-effect


【解决方案1】:

我会使用稍微不同的方法。

由于圆圈纯粹是为了装饰,不包含需要解释的信息,例如通过屏幕阅读器,我会将徽标完全包含在一个元素中,并将背景整体颜色放在该元素上,并将圆圈放在其之前的伪元素上。

然后使用 CSS 动画将具有径向渐变背景的圆圈一一绘制出来。

在这个 sn-p 中,所需的颜色定义为 CSS 变量 col1...,因此您可以在需要时轻松更改它们。动画通过一一设置径向渐变背景中的颜色来工作。

.logo {
  position: relative;
  width: 100vmin;
  height: 100vmin;
  background-color: #303030;
}

.logo::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: inline-block;
  --col1: #a5bc1f;
  --col2: #99ae21;
  --col3: #707d28;
  --col4: #4a4f2d;
  --c1: var(--col1);
  --c2: var(--col2);
  --c3: var(--col3);
  --c4: var(--col4);
  background-image: radial-gradient(var(--c1) 0 10%, var(--c2) 10% 20%, var(--c3) 20% 30%, var(--c4) 30% 40%, transparent 40% 100%);
}

.logo::before {
  animation: ripple 4s linear;
}

@keyframes ripple {
  0% {
    --c2: transparent;
    --c3: transparent;
    --c4: transparent;
    --c1: var(--col1);
  }
  33.33% {
    --c2: var(--col2);
  }
  66.66% {
    --c3: var(--col3);
  }
  100% {
    --c4: var(--col4);
  }
}
&lt;div class="logo"&gt;&lt;/div&gt;

注意:您需要更改径向渐变中的 %s 以获得您想要的效果(或者如果您希望在任何视口尺寸上具有完全相同的宽度,请更改为 px)。

更新:从后续的 cmets 中可以看出,这个问题实际上比上面给出的解决方案更简单。不是每个环都出现在一个步骤中,而是要求环生长直到它们达到所需的大小,然后下一个环生长。

我们可以通过在一个伪元素上一直使用多环背景来获得这种效果(不需要像上面那样动态地改变它)并且简单地从零开始增加它的大小,这样环就可以以连续的方式增长.

.logo {
  position: relative;
  width: 100vmin;
  height: 100vmin;
  --col1: #a5bc1f;
  --col2: #99ae21;
  --col3: #707d28;
  --col4: #4a4f2d;
}

.logo::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-image: radial-gradient(var(--col1) 0 10vmin, var(--col2) 10vmin 20vmin, var(--col3) 20vmin 30vmin, var(--col4) 30vmin 40vmin, transparent 40vmin 100vmin);
  animation: ripple 4s linear 1;
  animation-fill-mode: forwards;
  border-radius: 50%;
  z-index;
  -1;
}

@keyframes ripple {
  0% {
    width: 0;
    height: 0;
  }
  100% {
    width: 100vmin;
    height: 100vmin;
  }
}

.logo::before {
  content: '';
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  position: absolute;
  background-color: #303030;
  z-index: -2;
}
&lt;div class="logo"&gt;&lt;/div&gt;

【讨论】:

  • 非常感谢。请问我是否想在中心添加徽标​​并且仍然想显示四个圆圈我该怎么做?
  • 只需将徽标作为背景图像放在 .logo div 上,然后作为其背景图像的第一部分,背景位置中心和您想要的任何背景大小。
  • 非常感谢@A Haworth
  • 如果我想给一个效果,让它们可以淡出出现,所以效果很漂亮?
  • 对不起,我不完全理解。您是否希望每个环都淡入而不是立即出现?有。你试过动画不透明度?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-27
  • 2015-07-06
  • 2018-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多