css 精灵图动画制作
效果图
这里的精灵图主要是使用了 animation
样式,具体代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>精灵图动画制作</title>
<style>
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
position: relative;
}
.container {
left: calc(50% - 70px);
top: 140px;
position: absolute;
}
.box {
width: 140px;
height: 140px;
background: url(./bg.png);
animation: move 1s steps(12) infinite, move1 3s forwards;
position: absolute;
/* right: 0; */
left: 0;
background-color: rgb(111, 153, 140);
}
@keyframes move {
to {
background: url(./bg.png) -1680px 0;
}
}
@keyframes move1 {
to {
/* left: 50%; */
/* right: 50%; */
/* transform: translateX(-50%); */
}
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
使用的图片