为什么我的动画颜色变化有轻微延迟?
Why is there a slight delay in the color change in my animation?
如果你仔细观察动画,你会注意到颜色过渡有轻微的停顿,我想要更平滑的东西。我目前刚开始,我发现很难弄清楚为什么会这样。有人可以帮我解决这个问题并提供可能的解决方案吗?
.intro {
font-family: 'Playfair Display';
font-size: 49px;
color: rgb(255, 255, 255);
line-height: 0.9;
margin-top: 260px;
margin-left: 30px;
}
#intro-text {
animation-name: changeColor;
animation-duration: 5s;
animation-timing-function: ease-in;
animation-delay: 0s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
cursor: default;
transition: color 0.7s ease-in-out;
}
@keyframes changeColor{
0% {
color: rgb(255, 255, 255);
opacity: 0.2;
}
25% {
color: rgb(150, 131, 131);
opacity: 0.4;
}
50% {
color: rgb(140, 131, 131);
opacity: 0.6;
}
75% {
color: rgb(130, 121, 121,);
opacity: 0.8;
}
100% {
color: rgb(100, 091, 091);
opacity: 1;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,500; 0,600;0,700;0,800;0,900;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<link rel="shortcut icon" href="favicon2.png" type="image/x-icon">
<title>Why</title>
</head>
<body>
<div class="body">
<div class="intro">
<span id="intro-text">Hello! I'm an AI.</span><br>
</div>
</div>
</body>
</html>
.center {
margin: 0 auto;
}
.awesome {
font-family: futura;
font-style: italic;
width:100%;
margin: 0 auto;
text-align: center;
color:#313131;
font-size:45px;
font-weight: bold;
position: absolute;
-webkit-animation:colorchange 20s infinite alternate;
}
@-webkit-keyframes colorchange {
0% {
color: rgb(255, 255, 255);
opacity: 0.2;
}
10% {
color: #8e44ad;
}
20% {
color: #1abc9c;
}
30% {
color: #d35400;
}
40% {
color: blue;
}
50% {
color: #34495e;
}
60% {
color: blue;
}
70% {
color: #2980b9;
}
80% {
color: #f1c40f;
}
90% {
color: #2980b9;
}
100% {
color: pink;
}
}
<div class='center'>
<p class="awesome">Hello! I'm an AI.</p>
</div>
轻微的停顿是由于 25%、50% 和 75% 的关键帧选择器造成的。仅保留 0% 和 100% 选择器将产生平滑的动画。
.intro {
font-family: 'Playfair Display';
font-size: 49px;
color: rgb(255, 255, 255);
line-height: 0.9;
margin-top: 260px;
margin-left: 30px;
}
#intro-text {
animation-name: changeColor;
animation-duration: 5s;
animation-timing-function: ease-in;
animation-delay: 0s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
cursor: default;
transition: color 0.7s ease-in-out;
}
@keyframes changeColor{
0% {
color: rgb(255, 255, 255);
opacity: 0.2;
}
100% {
color: rgb(100, 091, 091);
opacity: 1;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,500; 0,600;0,700;0,800;0,900;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<link rel="shortcut icon" href="favicon2.png" type="image/x-icon">
<title>Why</title>
</head>
<body>
<div class="body">
<div class="intro">
<span id="intro-text">Hello! I'm an AI.</span><br>
</div>
</div>
</body>
</html>
将计时功能设置为 ease-in-out
动画 运行 在开始和结束时都很慢。
为了加快初始阶段 (0%),您可以设置不透明度从 0.4(或更多)开始。
如果你仔细观察动画,你会注意到颜色过渡有轻微的停顿,我想要更平滑的东西。我目前刚开始,我发现很难弄清楚为什么会这样。有人可以帮我解决这个问题并提供可能的解决方案吗?
.intro {
font-family: 'Playfair Display';
font-size: 49px;
color: rgb(255, 255, 255);
line-height: 0.9;
margin-top: 260px;
margin-left: 30px;
}
#intro-text {
animation-name: changeColor;
animation-duration: 5s;
animation-timing-function: ease-in;
animation-delay: 0s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
cursor: default;
transition: color 0.7s ease-in-out;
}
@keyframes changeColor{
0% {
color: rgb(255, 255, 255);
opacity: 0.2;
}
25% {
color: rgb(150, 131, 131);
opacity: 0.4;
}
50% {
color: rgb(140, 131, 131);
opacity: 0.6;
}
75% {
color: rgb(130, 121, 121,);
opacity: 0.8;
}
100% {
color: rgb(100, 091, 091);
opacity: 1;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,500; 0,600;0,700;0,800;0,900;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<link rel="shortcut icon" href="favicon2.png" type="image/x-icon">
<title>Why</title>
</head>
<body>
<div class="body">
<div class="intro">
<span id="intro-text">Hello! I'm an AI.</span><br>
</div>
</div>
</body>
</html>
.center {
margin: 0 auto;
}
.awesome {
font-family: futura;
font-style: italic;
width:100%;
margin: 0 auto;
text-align: center;
color:#313131;
font-size:45px;
font-weight: bold;
position: absolute;
-webkit-animation:colorchange 20s infinite alternate;
}
@-webkit-keyframes colorchange {
0% {
color: rgb(255, 255, 255);
opacity: 0.2;
}
10% {
color: #8e44ad;
}
20% {
color: #1abc9c;
}
30% {
color: #d35400;
}
40% {
color: blue;
}
50% {
color: #34495e;
}
60% {
color: blue;
}
70% {
color: #2980b9;
}
80% {
color: #f1c40f;
}
90% {
color: #2980b9;
}
100% {
color: pink;
}
}
<div class='center'>
<p class="awesome">Hello! I'm an AI.</p>
</div>
轻微的停顿是由于 25%、50% 和 75% 的关键帧选择器造成的。仅保留 0% 和 100% 选择器将产生平滑的动画。
.intro {
font-family: 'Playfair Display';
font-size: 49px;
color: rgb(255, 255, 255);
line-height: 0.9;
margin-top: 260px;
margin-left: 30px;
}
#intro-text {
animation-name: changeColor;
animation-duration: 5s;
animation-timing-function: ease-in;
animation-delay: 0s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
cursor: default;
transition: color 0.7s ease-in-out;
}
@keyframes changeColor{
0% {
color: rgb(255, 255, 255);
opacity: 0.2;
}
100% {
color: rgb(100, 091, 091);
opacity: 1;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,500; 0,600;0,700;0,800;0,900;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<link rel="shortcut icon" href="favicon2.png" type="image/x-icon">
<title>Why</title>
</head>
<body>
<div class="body">
<div class="intro">
<span id="intro-text">Hello! I'm an AI.</span><br>
</div>
</div>
</body>
</html>
将计时功能设置为 ease-in-out
动画 运行 在开始和结束时都很慢。
为了加快初始阶段 (0%),您可以设置不透明度从 0.4(或更多)开始。