代碼
提交代碼
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Animate</title>
<style>
/* 清除瀏覽器默認(rèn)邊距 */
* { padding: 0; margin: 0; }
/* 這段代碼是為了居中顯示,不是重點(diǎn),看不懂的話可以無視 */
body {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
/* 先定義動(dòng)畫,動(dòng)畫名叫:change-color */
@keyframes change-color {
from /* 0% */ { color: red } /* 紅 */
16% { color: orange } /* 橙 */
32% { color: yellow } /* 黃 */
48% { color: green } /* 綠 */
64% { color: cyan } /* 青 */
80% { color: blue } /* 藍(lán) */
to /* 100% */ { color: purple } /* 紫 */
}
.animate {
width: 400px;
height: 100px;
/* 再使用預(yù)先定義好的動(dòng)畫 */
animation: change-color 10s infinite;
/* 動(dòng)畫:動(dòng)畫名(change-color) 時(shí)長(zhǎng)(10秒) 動(dòng)畫次數(shù)(無限) */
}
</style>
</head>
<body>
<div class="animate">
<!-- 動(dòng)畫:動(dòng)畫名(change-color) 時(shí)長(zhǎng)(10秒) 動(dòng)畫次數(shù)(無限) -->
animation: change-color 10s infinite;
</div>
</body>
</html>
運(yùn)行結(jié)果