使用CSS 3动画但由于某些原因,所有动画在执行后都会返回其原始状态.
在这种情况下,我希望图像在动画之后保持比例(1),并且我的文本在img动画之后显示,但之后保持.
.expanding-spinning { -webkit-transform: scale(.4); -webkit-transition-timing-function: ease-out; -webkit-transition-duration: 500ms; animation-duration: 500ms; } .expanding-spinning { -webkit-animation: spin2 1.4s ease-in-out alternate; animation: spin2 1.4s ease-in-out alternate; -webkit-animation-delay: 2s; animation-delay: 2s; } @-webkit-keyframes spin2 { 0% { -webkit-transform: rotate(0deg) scale(.4);} 100% { -webkit-transform: rotate(360deg) scale(1);} } @-keyframes spin2 { 0% { transform: rotate(0deg) scale(.4);} 100% { transform: rotate(360deg) scale(1);} } @-webkit-keyframes fadeInFromNone { 0% { display:none; opacity: 0; } 100% { display: block; opacity: 1; } } .slogan { display: block; opacity: 1; -webkit-animation-duration: 2s; -webkit-animation-name: fadeInFromNone; -webkit-animation-delay: 3.5s; }
解决方法
您需要添加规则-webkit-animation-fill-mode:forwards;到你的动画.
.expanding-spinning { -webkit-animation: spin2 1.4s ease-in-out; -moz-animation: spin2 1.4s linear normal; -o-animation: spin2 1.4s linear; -ms-animation: spin2 1.4s linear; animation: spin2 1.4s ease-in-out alternate; -webkit-animation-delay: 2s; animation-delay: 2s; -webkit-animation-fill-mode: forwards; /* <--- */ } @-webkit-keyframes fadeInFromNone { 0% { visibility:hidden; opacity: 0; } 100% { visibility: visible; opacity: 1; } } .slogan { visibility:hidden; opacity: 1; -webkit-animation-duration: 2s; -webkit-animation-name: fadeInFromNone; -webkit-animation-delay: 3.4s; -webkit-animation-fill-mode: forwards; /* <--- */ }
有关所有动画属性的详细说明,请参阅this article
The fill mode. If set to forwards,the last keyframe remains at the
end of the animation,
(来自上面的链接)