【问题标题】:Why animating a div to move upwards and then right ends with a jump?为什么动画 div 向上移动然后以跳跃结束?
【发布时间】:2018-08-24 05:49:04
【问题描述】:

我正在学习动画,并试图让div(里面有一个input)向上然后向右移动。

向上的过渡看起来很流畅。然而,向右“跳跃”的过渡,并以更高的点结束(相对于前一个状态)。

我做错了什么?

代码:

.container {
  top: 30%;
  position: absolute;
  animation: move 5s 1;
}

input {
  width: 100px;
  height: 10px;
}

@keyframes move {
  0% {
    top: 30%;
  }
  50% {
    top: 10%;
  }
  100% {
    top: 10%;
    left: 20%;
  }
}
<div class="container">
  <input />
</div>

【问题讨论】:

    标签: css css-animations keyframe


    【解决方案1】:

    问题是您的left 没有已知的起始位置,因此它没有已知的动画开始位置。请尝试以下操作:

    .container {
      top: 30%;
      left: 0%;
      position: absolute;
      animation: move 5s 1;
    }
    
    input {
      width: 100px;
      height: 10px;
    }
    
    @keyframes move {
      0% {
        top: 30%;
        left: 0%;
      }
      50% {
        top: 10%;
        left: 0%;
      }
      100% {
        top: 10%;
        left: 20%;
      }
    }
    <div class="container">
      <input />
    </div>

    【讨论】:

      猜你喜欢
      • 2011-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多