小手动画
# 通过 background-size
、background-position
和 animation-timing-function: steps
配合实现。
# 图片大小4520 * 89,共40个小图,单个小图大小113 * 89,分别对应:
width: 113px; height: 89px;
background-size: 4570px 89px;
- 动画结束状态
to { background-position: -4570px 0; }
animation-timing-function: steps(40, end);
点击播放
<template>
<div class="demo-AnimateFinger">
<span>点击播放</span>
<i class="finger"></i>
</div>
</template>
<script>
export default {
name: 'AnimateFinger',
}
</script>
<style lang="scss" scoped>
.demo-AnimateFinger {
width: 240px;
height: 48px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
background-color: #f2571e;
color: #fff;
font-size: 24px;
font-weight: bold;
letter-spacing: 4px;
border-radius: 24px;
margin: 40px auto 50px;
cursor: pointer;
.finger {
width: 113px;
height: 89px;
background: url(//cdn.1024vip.cn/tech/images/202107/ec07fb0edb42d439473c9f974477b774.png) no-repeat;
background-position: 0;
background-size: 4570px 89px;
animation: hand-bounce 1150ms steps(40, end) infinite;
position: absolute;
right: -25px;
top: -6px;
}
@keyframes hand-bounce {
to {
background-position: -4570px 0;
}
}
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
上次更新: 2021-07-08 10:53:30