gpt4 book ai didi

html - 如何在两种颜色动画之间无限切换?

转载 作者:行者123 更新时间:2023-11-28 04:49:18 26 4
gpt4 key购买 nike

我是 CSS3 动画的新手,但我到处都找过了,找不到解决这个问题的方法。我有一个 JSP 页面,我希望背景从绿色慢慢淡化为蓝色,然后以相反的方式慢慢淡化,并无限重复这个过程。

我目前让它顺利地从绿色变为蓝色,但随后又立即变回蓝色。有没有办法播放两个动画,从绿到蓝,再从蓝到绿,无限重复?

这是我现在的 CSS 代码:

@keyframes changeColorGreenToBlue {
from { background-color: rgb(146,213,142);}
to {background-color: rgb(133,184,222);}
}
@keyframes changeColorBlueToGreen {
from {background-color: rgb(133,184,222);}
to { background-color: rgb(146,213,142);}
}
.jumbotron {
height: 100%;
width: 100%;
background-color: green;
animation: changeColorGreenToBlue ease;
animation-iteration-count: infinite;
animation-duration: 4s;
animation-fill-mode: both;
animation-name: changeColorBlueToGreen;
animation-iteration-count: infinite;
animation-duration: 4s;
background-size: cover;
background-repeat: repeat-y;
margin-bottom:1px;
}

它有点乱,因为我只是想方设法让它工作。对此感到抱歉!

最佳答案

您想要的不是两个关键帧动画,而是两次更改背景颜色的动画(一次是 50%,然后是 100%),如下所示:

@keyframes changeColor {
0% {
background-color: rgb(146,213,142);
}

50% {
background-color: rgb(133,184,222);
}

100% {
background-color: rgb(146,213,142);
}
}

参见 my codepen例如在行动中。

关于html - 如何在两种颜色动画之间无限切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36585661/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com