|
|

楼主 |
发表于 2023-3-19 21:43
|
显示全部楼层
关键帧动画驱动背景,就这么简单:
#papa::before {
position: absolute;
content: '';
width: 100px;
height: 100px;
background: url('https://638183.freep.cn/638183/t23/1/heart_133236768103332344.png') 0 0 no-repeat;
background-size: 2900%;
animation: chgBg steps(28) 2s infinite both;
animation-play-state: var(--state);
}
@keyframes chgBg {
0% { background-position: 0%; }
100% { background-position: 100%; }
}
设置好背景为长条图片。background-size 为 2900% 是依据图片宽度2900px而来。关键帧动画 chgBg 改变背景图片的位置,从 0% 到 100% 变化;而 animation 属性将动画分 28步(steps)走,因为动画开始时就在第一步(即第一个 100px),走到第28步时正好在2800px - 2900px 这一帧。
|
评分
-
| 参与人数 1 | 威望 +50 |
金钱 +100 |
经验 +50 |
收起
理由
|
红影
| + 50 |
+ 100 |
+ 50 |
赞一个! |
查看全部评分
|