关键帧动画回到初始状态
Keyframe animation back to initial state
我做了一个缓慢的无限 CSS3
动画。它从 top:0;
动画到 top:40px;
。错误是当动画结束时,它跳转到起点。我认为它应该用 ease
或 ease-in
跳转,但那没有发生。我尝试了很多来解决这个问题,但我失败了。
我需要 return 过渡才能产生 ease-in
效果。
我的代码:
span {
margin-left: 200px;
}
/** Down Slow Animation **/
@-webkit-keyframes downSlow {
from { top: 0px; }
to { top: 40px; }
}
@-moz-keyframes downSlow {
from { top: 0px; }
to { top: 40px; }
}
@keyframes downSlow {
from { top: 0px; }
to { top: 40px; }
}
.down-slow {
position: relative;
-webkit-animation: downSlow 1.5s infinite;
-moz-animation: downSlow 1.5s infinite;
animation: downSlow 1.5s infinite;
-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<span class="down-slow"><i class="fa fa-angle-down fa-5x"></i></span>
这只是一个替代方案
只需在 animation
的末尾添加 alternate
。
span {
margin-left: 200px;
}
/** Down Slow Animation **/
@-webkit-keyframes downSlow {
from { top: 0px; }
to { top: 40px; }
}
@-moz-keyframes downSlow {
from { top: 0px; }
to { top: 40px; }
}
@keyframes downSlow {
from { top: 0px; }
to { top: 40px; }
}
.down-slow {
position: relative;
-webkit-animation: downSlow 1.5s infinite alternate;
-moz-animation: downSlow 1.5s infinite alternate;
animation: downSlow 1.5s infinite alternate;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<span class="down-slow"><i class="fa fa-angle-down fa-5x"></i></span>
同样的代码可以简化为
span {
margin-left: 200px;
top: 0px;
}
@-webkit-keyframes downSlow {
to { top: 40px; }
}
@-moz-keyframes downSlow {
to { top: 40px; }
}
@keyframes downSlow {
to { top: 40px; }
}
.down-slow {
position: relative;
-webkit-animation: downSlow 1.5s infinite alternate;
-moz-animation: downSlow 1.5s infinite alternate;
animation: downSlow 1.5s infinite alternate;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<span class="down-slow"><i class="fa fa-angle-down fa-5x"></i></span>
更好的方法是使用 translate
这样您的元素就不会干扰其他 DOM 元素
span {
margin-left: 200px;
}
@-webkit-keyframes downSlow {
to { transform: translateY(40px) }
}
@-moz-keyframes downSlow {
to { transform: translateY(40px) }
}
@keyframes downSlow {
to { transform: translateY(40px) }
}
.down-slow {
position: relative;
-webkit-animation: downSlow 1.5s infinite alternate;
-moz-animation: downSlow 1.5s infinite alternate;
animation: downSlow 1.5s infinite alternate;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<span class="down-slow"><i class="fa fa-angle-down fa-5x"></i></span>
但是您可以再次使用 prefixfree frind a cdn here
来减少它
span {
margin-left: 200px;
}
@keyframes downSlow {
to { transform: translateY(40px) }
}
.down-slow {
position: relative;
animation: downSlow 1.5s infinite alternate;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<span class="down-slow"><i class="fa fa-angle-down fa-5x"></i></span>
最后设置speed/2
span {
margin-left: 200px;
}
@keyframes downSlow {
to { transform: translateY(40px) }
}
.down-slow {
position: relative;
animation: downSlow .7s infinite alternate forwards;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<span class="down-slow"><i class="fa fa-angle-down fa-5x"></i></span>
REF: animation-fill-mode
我做了一个缓慢的无限 CSS3
动画。它从 top:0;
动画到 top:40px;
。错误是当动画结束时,它跳转到起点。我认为它应该用 ease
或 ease-in
跳转,但那没有发生。我尝试了很多来解决这个问题,但我失败了。
我需要 return 过渡才能产生 ease-in
效果。
我的代码:
span {
margin-left: 200px;
}
/** Down Slow Animation **/
@-webkit-keyframes downSlow {
from { top: 0px; }
to { top: 40px; }
}
@-moz-keyframes downSlow {
from { top: 0px; }
to { top: 40px; }
}
@keyframes downSlow {
from { top: 0px; }
to { top: 40px; }
}
.down-slow {
position: relative;
-webkit-animation: downSlow 1.5s infinite;
-moz-animation: downSlow 1.5s infinite;
animation: downSlow 1.5s infinite;
-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<span class="down-slow"><i class="fa fa-angle-down fa-5x"></i></span>
这只是一个替代方案
只需在 animation
的末尾添加 alternate
。
span {
margin-left: 200px;
}
/** Down Slow Animation **/
@-webkit-keyframes downSlow {
from { top: 0px; }
to { top: 40px; }
}
@-moz-keyframes downSlow {
from { top: 0px; }
to { top: 40px; }
}
@keyframes downSlow {
from { top: 0px; }
to { top: 40px; }
}
.down-slow {
position: relative;
-webkit-animation: downSlow 1.5s infinite alternate;
-moz-animation: downSlow 1.5s infinite alternate;
animation: downSlow 1.5s infinite alternate;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<span class="down-slow"><i class="fa fa-angle-down fa-5x"></i></span>
同样的代码可以简化为
span {
margin-left: 200px;
top: 0px;
}
@-webkit-keyframes downSlow {
to { top: 40px; }
}
@-moz-keyframes downSlow {
to { top: 40px; }
}
@keyframes downSlow {
to { top: 40px; }
}
.down-slow {
position: relative;
-webkit-animation: downSlow 1.5s infinite alternate;
-moz-animation: downSlow 1.5s infinite alternate;
animation: downSlow 1.5s infinite alternate;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<span class="down-slow"><i class="fa fa-angle-down fa-5x"></i></span>
更好的方法是使用 translate
这样您的元素就不会干扰其他 DOM 元素
span {
margin-left: 200px;
}
@-webkit-keyframes downSlow {
to { transform: translateY(40px) }
}
@-moz-keyframes downSlow {
to { transform: translateY(40px) }
}
@keyframes downSlow {
to { transform: translateY(40px) }
}
.down-slow {
position: relative;
-webkit-animation: downSlow 1.5s infinite alternate;
-moz-animation: downSlow 1.5s infinite alternate;
animation: downSlow 1.5s infinite alternate;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<span class="down-slow"><i class="fa fa-angle-down fa-5x"></i></span>
但是您可以再次使用 prefixfree frind a cdn here
来减少它span {
margin-left: 200px;
}
@keyframes downSlow {
to { transform: translateY(40px) }
}
.down-slow {
position: relative;
animation: downSlow 1.5s infinite alternate;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<span class="down-slow"><i class="fa fa-angle-down fa-5x"></i></span>
最后设置speed/2
span {
margin-left: 200px;
}
@keyframes downSlow {
to { transform: translateY(40px) }
}
.down-slow {
position: relative;
animation: downSlow .7s infinite alternate forwards;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<span class="down-slow"><i class="fa fa-angle-down fa-5x"></i></span>
REF: animation-fill-mode