- alternate 偶数次逆向执行
- infinite 永远执行
- forwards 停止在最后结束状态
开始帧和结束帧动画
盒子大小由0倍变为2倍,偶数次逆向执行,永远执行
<!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">
<title>Document</title>
<style>
div {
margin: 100px auto;
width: 200px;
height: 200px;
background-color: orange;
animation: bigger 1s linear 0s alternate infinite;
}
@keyframes bigger {
from {
transform: scale(0);
}
to {
transform: scale(2);
}
}
</style>
</head>
<body>
<div></div>
</body>
</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">
<title>Document</title>
<style>
div {
margin: 100px auto;
width: 200px;
height: 200px;
background-color: orange;
animation: changeColor 3s linear 0s forwards;
}
@keyframes changeColor {
0% {
background-color: orange;
}
20% {
background-color: yellow;
}
40% {
background-color: blue;
}
60% {
background-color: green;
}
80% {
background-color: purple;
}
100% {
background-color: red;
}
}
</style>
</head>
<body>
<div></div>
</body>
</html>