我有以下代码,可以对元素的背景位置进行动画处理以创建关键帧动画。它是 12 帧,图像是 1536px。
但是,即使我有 -webkit-animation-fill-mode:forwards;
动画在最后会重置回第一帧...我该如何停止?
HTML:
<div class="sequence animate"></div>
CSS:
div.sequence
{
width: 128px;
height: 128px;
background: url('./img/sequence.png');
}
div.sequence.animate
{
-webkit-animation: boxopen 4s steps(12);
-webkit-animation-fill-mode: forwards;
}
@-webkit-keyframes boxopen {
from {background-position: 0;}
to {background-position: -1536px;}
}
最佳答案
您的图像会重复,因此到第 12 帧时,图像完全向左偏移,并且您会看到它的开头重复。只需在 11 个步骤后停止动画即可:
div.sequence
{
width: 128px;
height: 128px;
background: url('http://i60.tinypic.com/1otwkg.png');
}
div.sequence.animate
{
-webkit-animation: boxopen 6s steps(11); /* 11 steps not 12 */
-webkit-animation-fill-mode: forwards;
}
@-webkit-keyframes boxopen {
from {background-position: 0;}
to {background-position: -1408px;} /* stop at the left of frame 12 */
}
<div class="sequence animate"></div>
关于html - CSS 动画在结束时重置为第一个关键帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27918814/