<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
width: 140px;
height: 140px;
border: 1px so red;
background-image: url(./images/bg.png);
animation: run 1s steps(12) infinite , move 2s linear forwards;
}
@keyframes run {
100% {
background-position: -1680px 0;
}
}
@keyframes move {
100% {
transform: translate(1000px ,0);
}
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
根据图片数量设置帧数和动画时间
steps(数字)帧数