【问题标题】:Unable to animate transform: scale and box-shadow simultaneously无法动画变换:同时缩放和阴影
【发布时间】:2018-03-23 13:52:55
【问题描述】:

我需要为圆的box-shadow 设置动画,并在box-shadow 的同一过渡期内将其从 1.6 倍缩小到 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>

Fiddle

【问题讨论】:

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


    【解决方案1】:

    当您的 transform: scale(1.6) 时,您的 box-shadow 变为 transparent 之后,当您转到 scale(1) 时,您的 box-shadow 正在动画,但您看不到它,因为它是透明的...所以更改 @987654325 @颜色

    在代码中也改变了比例值...

    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>

    【讨论】:

    • 那行得通。我没有看到rgbaa 值的变化。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-12
    • 1970-01-01
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 1970-01-01
    相关资源
    最近更新 更多