【前端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%);
    }
}
相关推荐
梦帮科技6 小时前
Node.js配置生成器CLI工具开发实战
前端·人工智能·windows·前端框架·node.js·json
VT.馒头7 小时前
【力扣】2695. 包装数组
前端·javascript·算法·leetcode·职场和发展·typescript
css趣多多7 小时前
一个UI内置组件el-scrollbar
前端·javascript·vue.js
C澒7 小时前
前端整洁架构(Clean Architecture)实战解析:从理论到 Todo 项目落地
前端·架构·系统架构·前端框架
C澒8 小时前
Remesh 框架详解:基于 CQRS 的前端领域驱动设计方案
前端·架构·前端框架·状态模式
Charlie_lll8 小时前
学习Three.js–雪花
前端·three.js
onebyte8bits8 小时前
前端国际化(i18n)体系设计与工程化落地
前端·国际化·i18n·工程化
C澒8 小时前
前端分层架构实战:DDD 与 Clean Architecture 在大型业务系统中的落地路径与项目实践
前端·架构·系统架构·前端框架
BestSongC8 小时前
行人摔倒检测系统 - 前端文档(1)
前端·人工智能·目标检测
0思必得09 小时前
[Web自动化] Selenium处理滚动条
前端·爬虫·python·selenium·自动化