【问题标题】:Making a wave animation制作波浪动画
【发布时间】:2015-10-23 22:15:33
【问题描述】:

我正在尝试制作音频波动画。这段代码有什么问题? 我试图将翻译更改为比例,但没有奏效。谁能给我一些动画练习的链接?

* {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-perspective: 1000px;
  perspective: 1000px;
}
div {
  width: 400px;
  height: 200px;
  margin: 50px auto;
}
span {
  display: inline-block;
  background-color: green;
  width: 20px;
  height: 20px;
  animation: wave 2s linear infinite;
}
.a1 {
  animation-delay: 0s;
}
.a2 {
  animation-delay: .2s;
}
.a3 {
  animation-delay: .4s;
}
.a4 {
  animation-delay: .6s;
}
.a5 {
  animation-delay: .8s;
}
@keyframes wave {
  0%, 50%, 75%, 100% {
    height: 5px;
    transform: translateY(0px);
  }
  25% {
    height: 30px;
    transform: translateY(15px);
    background-color: palevioletred;
  }
}
<div>
  <span class="a1"></span>
  <span class="a2"></span>
  <span class="a3"></span>
  <span class="a4"></span>
  <span class="a5"></span>
</div>

wave ,代码正在运行,但它没有显示为 wave

【问题讨论】:

  • animate.css 挺好的,google 一下 :)

标签: html css css-animations


【解决方案1】:

您可以通过动画transform property 而不是元素的高度来移除元素的上下移动。

您可以使用 scaleY() 函数使元素在 Y 轴(高度)上增长。

例子:

* {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-perspective: 1000px;
  perspective: 1000px;
}
div {
  width: 400px;
  height: 200px;
  margin: 50px auto;
}
span {
  display: inline-block;
  background-color: green;
  width: 20px;
  height: 20px;
  animation: wave 2s linear infinite;
}
.a1 {
  animation-delay: 0s;
}
.a2 {
  animation-delay: .2s;
}
.a3 {
  animation-delay: .4s;
}
.a4 {
  animation-delay: .6s;
}
.a5 {
  animation-delay: .8s;
}
@keyframes wave {
  0%, 50%{
    transform: scaleY(1);
  }
  25% {
    transform: scaleY(4);
    background-color: palevioletred;
  }
}
<div>
  <span class="a1"></span>
  <span class="a2"></span>
  <span class="a3"></span>
  <span class="a4"></span>
  <span class="a5"></span>
</div>

【讨论】:

  • 谢谢它的工作,但为什么使用翻译 Y 不起作用?
  • @LCTS translateY 将使元素在 Y 轴上移动,而 scaleY 将使其在 Y 轴上增长或缩小。
猜你喜欢
  • 1970-01-01
  • 2017-12-10
  • 2017-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-14
  • 2020-08-11
  • 2017-11-10
相关资源
最近更新 更多