css sprite 雪碧图实现推特的点赞动画

资料

原文地址 CSS sprite sheet animations

效果演示

演示.gif
  • 源码
<!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 {
                background-color: #202283;
                background-image: linear-gradient(#34369b 1px, transparent 1px),
                    linear-gradient(90deg, #34369b 1px, transparent 1px),
                    linear-gradient(#272992 1px, transparent 1px),
                    linear-gradient(90deg, #272992 1px, #202283 1px);
                background-size: 96px 96px, 96px 96px, 12px 12px, 12px 12px;
                background-position: -1px -1px, -1px -1px, -1px -1px, -1px -1px;
                border-radius: 12px;
            }
            .element {
                background-image: url('./twitter.png');
                /* size of one frame */
                width: 100px;
                height: 100px;
                /* size of the whole sheet */
                background-size: 2900px 100px;
                /* coordinates of the desired frame (negated) */
                background-position: 0 0px;
                /* animate the coordinates */
            }
            .element:hover {
                animation: heartAnimation 2s steps(29, jump-none) infinite;
            }

            @keyframes heartAnimation {
                from {
                    /* first frame */
                    background-position: 0px 0px;
                }
                to {
                    /* last frame */
                    background-position: -2800px 0px;
                }
            }
        </style>
    </head>
    <body>
        <div class="element"></div>
    </body>
</html>

  • 代码中使用的雪碧图
twitter.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容