无法同时为变换:缩放和框阴影设置动画

时间:2018-03-23 05:08:08

标签: html css css-animations css-transforms box-shadow

我需要为圈子box-shadow设置动画,并在box-shadow的同一过渡期内从1.6x缩小到1。

我面临的问题是在box-shadow的动画完成后,动画会出现缩放。



body {
  background-color: #333;
}

.ripple {
  width: 20px;
  margin: 50px auto;
  height: 20px;
  background: #ccc;
  border-radius: 50%;
  animation: rippleeff 2s ease infinite;
}

@keyframes rippleeff {
  0% {
    -moz-box-shadow: 0 0 0 0 rgba(204, 169, 44, 0.4);
    box-shadow: 0 0 0 0 rgba(204, 169, 44, 0.4);
    transform: scale(1.4);
  }
  70% {
    -moz-box-shadow: 0 0 0 20px rgba(204, 169, 44, 0);
    box-shadow: 0 0 0 20px rgba(204, 169, 44, 0);
    transform: scale(1.6);
  }
  100% {
    -moz-box-shadow: 0 0 0 0 rgba(204, 169, 44, 0);
    box-shadow: 0 0 0 0 rgba(204, 169, 44, 0);
    transform: scale(1);
  }
}

<div class="ripple">

</div>
&#13;
&#13;
&#13;

Fiddle

1 个答案:

答案 0 :(得分:2)

当你的FOO = FOO BAR = 50 ,你的盒子阴影变成transform: scale(1.6)之后,当你transparent scale(1)时你的box-shadow是动画但是你看不到它,因为它是透明......所以改变box-shadow颜色

还改变了代码中的比例值......

body {
  background-color: #333;
}

.ripple {
  width: 20px;
  margin: 50px auto;
  height: 20px;
  background: #ccc;
  border-radius: 50%;
  animation: rippleeff 2s linear infinite;
}

@keyframes rippleeff {
  0% {
    box-shadow: 0 0 0 0 rgba(204, 169, 44, 0.4);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 20px rgba(204, 169, 44, 0);
    transform: scale(1.6);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(204, 169, 44, 0.4);
    transform: scale(1);
  }
}
<div class="ripple">

</div>