<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.hi{
width: 50px;
height: 72px;
background-image: url("http://s.cdpn.io/79/sprite-steps.png");
/*深度理解
*整个动画1s完成。
*这里1s要移动500的像素,这1s要有十步走完,每步是平均下来是0.1s,
*每步比上一步多走了72px的位置,这个走是瞬间走到的。
*end表示每一步在接近0.1s再去走
*/
/* animation: play 1s steps(10,end) infinite; */
animation: play 1s steps(10,start) infinite;
}
/*定义动画*/
@keyframes play {
from { background-position: 0px 0px; }
to { background-position: -500px 0px; }
}
</style>
</head>
<body>
<img src="http://s.cdpn.io/79/sprite-steps.png" alt="此图片是500*72,主要是为了显示作用">
<div class="hi"></div>
</body>
</html>
参考:https://blog.csdn.net/LY_code/article/details/80209183?utm_source=blogxgwz0
animation-fill-mode : none | forwards | backwards | both;
none 不改变默认行为。 forwards 当动画完成后,保持最后一个属性值(在最后一个关键帧中定义)。 backwards 在 animation-delay 所指定的一段时间内,在动画显示之前,应用开始属性值(在第一个关键帧中定义)。 both 向前和向后填充模式都被应用。