为什么动画 div 向上移动然后向右以跳跃结束?
Why animating a div to move upwards and then right ends with a jump?
我正在学习动画,并尝试让 div
(里面有一个 input
)向上然后向右移动。
向上的过渡看起来很顺利。但是,向右过渡 "jumps",并在更高的点结束(相对于之前的状态)。
我做错了什么?
代码:
.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>
问题是您的 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>
我正在学习动画,并尝试让 div
(里面有一个 input
)向上然后向右移动。
向上的过渡看起来很顺利。但是,向右过渡 "jumps",并在更高的点结束(相对于之前的状态)。
我做错了什么?
代码:
.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>
问题是您的 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>