@keyframes无法使用%

时间:2018-05-22 11:15:49

标签: html5 css3 css-animations

.car1仅在使用@keyframes的{​​{1}}& from,但在使用to时没有。任何人都能解释为什么会这样吗?

%
.car1 {
  animation: car1 2s 2 forwards;
  position: absolute;
}

@keyframes car1 {
  from {transform: translateX(550px)}
  to {transform: translateX(-550px)}
}

.car2 {
  position: absolute;
  top: 0;
  animation: car2 2s 2 forwards;
}

@keyframes car2 {
  0% {top: 30px}
  25% {top: 130px}
  40% {top: 230px}
  75% {top: 330px}
}

1 个答案:

答案 0 :(得分:0)

.car1 {
  animation: car1 2s 2 forwards;
  position: absolute;
}

@keyframes car1 {
  0% {transform: translateX(550px)}
  100% {transform: translateX(-550px)}
}

.car2 {
  position: absolute;
  top: 0;
  animation: car2 2s 2 forwards;
}

@keyframes car2 {
  0% {top: 30px}
  25% {top: 130px}
  40% {top: 230px}
  75% {top: 330px}
}
<div class="car1">Car1</div>
<div class="car2">Car2</div>
嘿,只需在@keyframes car1中从0%设置为100%就可以正常工作了!