我正在学习如何在 CSS 中制作动画。我知道我可以将iteration-count
属性设置为无限,它会无限期地运行,但我希望循环是平滑的。在关键帧中回到 0% 后,动画不平滑并立即更改为该属性。如果有意义的话,我希望从 100% 到 0% 的过渡能够顺利进行。
这是我的 HTML
<!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="stylesheet" href="style.css">
<title>CSS Animations</title>
</head>
<body>
<div id="shape"></div>
</body>
</html>
这是我的 CSS
*
{
margin:0px;
padding:0px;
}
body
{
display: flex;
justify-content: center;
align-items: center;
height:100vh;
}
#shape
{
background-color: red;
width:100px;
height:100px;
border-radius:50%;
border:0px;
animation-name:color-function;
animation-duration: 5s;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-fill-mode: forwards;
}
@keyframes color-function
{
0%
{
background-color: red;
height:100px;
border-radius: 50%;
}
25%
{
background-color: yellow;
height:100px;
border-radius: 50%;
}
50%
{
background-color: blue;
height:100px;
border-radius: 50%;
}
75%
{
background-color: green;
height:100px;
border-radius: 50%;
}
100%
{
background-color: red;
height:150px;
border-radius: 0%;
}
}
谢谢