【前端demo】背景渐变动画

其他demo

效果

在这里插入图片描述

效果预览:https://codepen.io/karshey/pen/OJrXZwQ

过程

注意,直接在body上加height:100%可能也会出现height为0的情况,这是需要令html的height:100%

代码

html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS-Color-Changing-Background</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    
</body>
</html>

css

html {
    /* 若没有这行可能导致body的height为0 */
    /* Edge浏览器中没有这行body也有高度,且占满整行 */
    height: 100%;
}

body {
    height: 100%;
    animation-name: colorChange;
    animation-duration: 10s;
    animation-iteration-count: infinite;
    animation-delay: 0s;
    background-color: rgb(255, 255, 255);
}

@keyframes colorChange {


    0% {
        background-image: linear-gradient(120deg, #a18cd1 0%, #fbc2eb 100%);
    }

    20% {
        background-image: linear-gradient(120deg, #fbc2eb 0%, #a6c1ee 100%);
    }

    30% {
        background-image: linear-gradient(120deg, #a1c4fd 0%, #c2e9fb 100%);
    }

    40% {
        background-image: linear-gradient(120deg, #d4fc79 0%, #96e6a1 100%);
    }

    50% {
        background-image: linear-gradient(120deg, #e0c3fc 0%, #8ec5fc 100%);
    }

    60% {
        background-image: linear-gradient(120deg, #0fd850 0%, #f9f047 100%);
    }

    70% {
        background-image: linear-gradient(120deg, #b224ef 0%, #7579ff 100%);
    }

    80% {
        background-image: linear-gradient(120deg, #df89b5 0%, #bfd9fe 100%);
    }

    100% {
        background-image: linear-gradient(to right, #0acffe 0%, #495aff 100%);
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

karshey

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值