【前端demo】背景渐变动画

文章目录

其他demo

效果

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

过程

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

代码

html

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

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%);
    }
}
相关推荐
wordbaby6 小时前
一次微信小程序 `web-view` 跳转原生页回跳后 H5 白屏的排查与修复(Hash 路由污染)
前端
用户721880438356 小时前
密码骰子:结合AIUI在眼镜上生成一串16位密码
前端
江华森6 小时前
全链路可观测落地记:kube-prometheus-stack 在 K3s 上的 8 个坑与一整套修复脚本
前端
deli0076 小时前
27 寸 4K 开 125% 为什么发虚?PPI 和缩放一次算清
前端
广州华水科技6 小时前
当大坝面临风险时,如何有效实施单北斗GNSS变形监测?
前端
AiMan7 小时前
Poe还是不可以导出左侧所有对话,只能单条内容导出,方法不对吗
前端
AiMan8 小时前
文心生成的内容能否下载吗?
前端
前端双越老师8 小时前
程序员 1v1 访谈系列第十四期:接受焦虑 拥抱不确定
前端·ai编程·全栈
deli0079 小时前
MCP 协议 6 条消息拆开看:AI 为什么能自己读文件调接口
前端