JAYbranding

使用 CSS 为 PNG 图片制作动画

<style> .animatediv{ width: 951px; height: 979px; background-color: #ccc; margin: 0 auto; background-image: url('/media/2022/09/x-men-animate.png'); animation: play 1s steps(7) infinite; } @keyframes play { from { background-position: 0px; } to { background-position: -6657px; } } </style> <pre data-line=""> <code readonly="true"> <xmp> <style> .animatediv{ background-color: #ccc; margin: 0 auto; / 单帧的宽度和高度 / width: 951px; height: 979px; / 加载合并图片的背景图 / background-image: url('/media/2022/09/x-men-animate.png'); / 播放动画,将数字 7 替换为合并的图片数量 / animation: play 1s steps(7) infinite; } @keyframes play { from { background-position: 0px; } / 替换为图片的宽度 / to { background-position: -6657px; } } </style></xmp> </code> </pre>