【前端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%);
    }
}
相关推荐
问心无愧05132 小时前
ctf show web入门160 161
前端·笔记
李小白662 小时前
第四天-WEB服务器基本原理,IIS服务
运维·服务器·前端
humcomm3 小时前
AI编程时代新前端职位
前端·ai编程
好家伙VCC3 小时前
Web Components主题热切换方案揭秘
java·前端
甲维斯4 小时前
Kimi版超级玛丽效果“惊人”,配额不足5厘米!
前端·人工智能
hboot4 小时前
AI工程师第一课 - Python
前端·后端·python
凉菜凉凉4 小时前
AI时代,被抛弃的前端
前端·ai
console.log('npc')4 小时前
AI前端工程与生成式UI学习路线
前端·人工智能·ui
梦曦i4 小时前
uni-router v1.1.1发布:守卫超时保护+路由监听
前端·uni-app
qq_2518364575 小时前
基于java Web网络订餐系统设计与实现 源码文档
java·开发语言·前端