HTML爱心动画小玩意儿

哈喽,今天新学了一个HTML技巧,是关于动画的啦,给大家看看成果
是不是很好看呢,背景图片星空那样的还不会,先这样吧

下面是源码

<!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;
            animation: colorChange 6s linear infinite alternate;
        }

        .heart {
            width: 400px;
            height: 400px;
            margin: 100px auto;
        }

        .yue {
            float: left;
            width: 200px;
            height: 200px;
        }

        .left,
        .right {
            float: left;
            width: 100px;
            height: 160px;
            background-color: pink;
            border-radius: 50px 50px 0 0;
        }

        .left {
            transform: translateX(-28px) rotate(45deg);
            /* transform:translateX位移,以x轴为准; */
        }

        .right {
            transform: translateX(30px) rotate(-45deg);
        }

        /* 选择heart下的第二个you 【子元素】*/
        .you:nth-child(2) {
            animation: move 6s linear infinite alternate;
            /* 播放/绑定动画 绑定函数 时间 速度【匀速】 次数【循环【反向】】 */
        }

        .you:nth-child(2) .left,
        .you:nth-child(2) .right {
            animation: colorChange 6s linear infinite alternate;
        }

        @keyframes move {
            0% {
                /* 动画开始的画面 */
                transform: translate(0px);
            }

            100% {
                /* 动画结束的画面 */
                transform: translate(-400px);
            }
        }

        @keyframes colorChange {
            0% {
                background-color: skyblue;
            }

            50% {
                background-color: black;
            }

            100% {
                background-color: skyblue;
            }

        }
    </style>
</head>

<body>
    <div class="heart">
        <div class="you">
            <div class="right"></div>
            <div class="left"></div>
        </div>
        <div class="you">
            <div class="right"></div>
            <div class="left"></div>
        </div>
    </div>
</body>

</html>
  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值