gpt4 book ai didi

html - CSS 动画背景颜色问题

转载 作者:行者123 更新时间:2023-11-28 00:31:35 25 4
gpt4 key购买 nike

作为 CSS 动画的新手,我有一些无法弄清楚背景颜色的问题。

所以我希望在动画之前有一个延迟,然后背景从左到右填充,这是有效的,但问题是延迟的初始背景颜色是#73A7CE,然后闪烁到较浅的颜色#9BD5FF。

有没有办法将#9BD5FF 作为初始颜色,而#73A7CE 仅随动画一起出现以创建加载类型效果?

html {
box-sizing: border-box;
font-size: 62.5%;
-webkit-overflow-scrolling: touch;
}

*, *:before, *:after { box-sizing: inherit; }

body {
background: #282828;
color: #333;
font-family: "Open Sans", sans-serif;
font-size: 1.6rem;
line-height: 1.5;
margin: 0;
}

.content__wrapper {
display: flex;
justify-content: center;
margin-top: 4rem;
}

.promo__btn {
align-items: center;
animation: btn-bg-animation 5s;
animation-delay: 4s;
animation-timing-function: linear;
background: linear-gradient(to right, #73A7CE 50%, #9BD5FF 50%);
background-size: 200%;
display: flex;
font-size: 2rem;
font-weight: 600;
height: 6rem;
justify-content: center;
padding-left: 1.8rem;
padding-right: 1.8rem;
width: 37.4rem;
}


@keyframes btn-bg-animation {
from {
background-position: right;
}

to {
background-position:left;
}
}
<section class="content__wrapper">
<div class="promo__btn">
<span>Button</span>
</div><!-- /.promo__btn -->
</section><!-- /.content__wrapper -->

如果我没有完整解释,请告诉我,我会添加更多详细信息。

最佳答案

使用 2 层而不是一层并将动画应用于顶层的 background-size:

body {
background: #282828;
color: #333;
}

.promo__btn {
animation: btn-bg-animation 5s 4s linear forwards;
background:
linear-gradient(#9BD5FF, #9BD5FF),
#73A7CE;
background-size: 0 100%;
background-repeat: no-repeat;

display: flex;
font-size: 1.5rem;
font-weight: 600;
height: 6rem;
justify-content: center;
align-items: center;
width: 27.4rem;
margin: 20px auto;
}

@keyframes btn-bg-animation {
to {
background-size: 100% 100%;
}
}
<div class="promo__btn">
<span>Watch Me Fade Away...</span>
</div>

关于html - CSS 动画背景颜色问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58641264/

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