html - 如何创建平滑渐变背景动画?
问题描述
我创建了一个div
有渐变背景的,我想改变这个渐变。我应用了一个关键帧动画,它立即改变了背景颜色。我怎样才能使这种变化顺利进行?
div {
width: 100px;
height: 100px;
background:linear-gradient(red, yellow);
animation-name: colorchange;
animation-duration: 5s;
-webkit-animation-name: colorchange;
animation-iteration-count: 5;
-webkit-animation-duration: 5s;
text-align: center;
}
@keyframes colorchange {
0% {background:linear-gradient(red, yellow) }
35% {background:linear-gradient(yellow, green) }
70% {background:linear-gradient(green, red) }
100%{background:linear-gradient(red, yellow)}
}
<div>
Gradient Background
</div>
解决方案
尝试这个
div {
text-align: center;
width: 100px;
height: 90px;
color: #fff;
background: linear-gradient(0deg, red, yellow, green);
background-size: 400% 400%;
-webkit-animation: Gradient 15s ease infinite;
-moz-animation: Gradient 15s ease infinite;
animation: Gradient 15s ease infinite;
}
@-webkit-keyframes Gradient {
0% {
background-position: 50% 0%
}
50% {
background-position: 50% 100%
}
100% {
background-position: 50% 0%
}
}
@-moz-keyframes Gradient {
0% {
background-position: 50% 0%
}
50% {
background-position: 50% 100%
}
100% {
background-position: 50% 0%
}
}
@keyframes Gradient {
0% {
background-position: 50% 0%
}
50% {
background-position: 50% 100%
}
100% {
background-position: 50% 0%
}
}
<div> Text </div>
推荐阅读
- javascript - 试图在开发者工具中找到“x-onclick”属性的功能
- php - 在用户的发件箱中使用 PHP 发送邮件?
- r - 创建一个以外部列表为条件的新变量
- linux - 用于将 2 个 Rpi 同步为从属设备的 PTPD 与 1 个主设备在 30 分钟后停止为 1 个从属设备工作
- postgresql - 将文本文件复制为字符串
- sql - 聚合后的不同值
- excel - 在 VBA 中根据循环范围保存文件
- c# - 使用远程处理时解决与 DLL 版本冲突的任何方法。点网框架 4.8
- c# - 如何在 ASP.NET Web 应用程序中热交换重建的数据库
- elasticsearch - 弹性搜索重新索引 API - 如何保留目标索引映射?