Joh*_*nny 44 animation webkit css3
我正在制作一个CSS动画,在那里,我正在移动东西,并希望它保持在最终位置,直到用户将鼠标移开.
body {
background: url('osx.jpg');
padding: 0;
margin: 0;
line-height: 60px;
}
@-webkit-keyframes item1 {
0% { bottom: -120px; left: 0px; }
10% { bottom: -40px; left: 10px; -webkit-transform: rotate(5deg); }
100% { bottom: -40px; left: 10px; -webkit-transform: rotate(5deg); }
}
@-webkit-keyframes item2 {
0% { bottom: -120px; left: 0px; }
10% { bottom: 60px; left: 20px; -webkit-transform: rotate(7deg); }
100% { bottom: 60px; left: 20px; -webkit-transform: rotate(7deg); }
}
@-webkit-keyframes item3 {
0% { bottom: -120px; left: 0px; }
10% { bottom: 160px; left: 30px; -webkit-transform: rotate(9deg); }
100% { bottom: 160px; left: 30px; -webkit-transform: rotate(9deg); }
}
div {
position: relative;
}
#folder {
width: 120px;
margin: 0px auto;
}
#folder > div {
position: absolute;
}
#folder:hover > div:nth-of-type(1) {
-webkit-animation-name: item1;
-webkit-animation-duration: 10s;
}
#folder:hover > div:nth-of-type(2) {
-webkit-animation-name: item2;
-webkit-animation-duration: 10s;
}
#folder:hover > div:nth-of-type(3) {
-webkit-animation-name: item3;
-webkit-animation-duration: 10s;
}
Run Code Online (Sandbox Code Playgroud)
每当动画结束时,它就会重复.我只希望它发生一次并保持原状直到用户离开.我尝试使用规范中的暂停的东西,但它不能像我期望的那样工作.任何帮助表示赞赏.谢谢.:)
ian*_*her 99
以下评论对我有用.谢谢迈克尔
"您需要添加填充模式以在动画结束时冻结动画状态.
-webkit-animation-fill-mode: forwards;
Run Code Online (Sandbox Code Playgroud)
forwards 将动画保留在最后一帧的状态
backwards 在开始时离开动画
Mr_*_*uet 15
如果您的动画仍然重置为第一帧,请注意声明css 的顺序:
这很好用:
animation: yourAnimationName 1s;
animation-fill-mode: forwards;
Run Code Online (Sandbox Code Playgroud)
这不会(重置为第一帧):
animation-fill-mode: forwards;
animation: yourAnimationName 1s;
Run Code Online (Sandbox Code Playgroud)
整蛊!