代碼
提交代碼
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Animate</title>
<style>
/* 清除瀏覽器默認(rèn)邊距 */
* { padding: 0; margin: 0; }
/* 這段代碼是為了居中顯示,不是重點,看不懂的話可以無視 */
body {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
/* 先定義動畫,動畫名叫:change-color */
@keyframes change-color {
from /* 0% */ { color: red } /* 紅 */
to /* 100% */ { color: purple } /* 為了方便直接從紅到紫 */
}
.animate {
width: 450px;
height: 100px;
/* 再使用預(yù)先定義好的動畫 */
animation: change-color 1s infinite alternate;
/* 動畫:動畫名(change-color) 時長(1秒) 動畫次數(shù)(無限) 動畫方向(交替運行) */
}
</style>
</head>
<body>
<div class="animate">
<!-- 動畫:動畫名(change-color) 時長(1秒) 動畫次數(shù)(無限) 動畫方向(交替運行) -->
animation: change-color 1s infinite alternate;
</div>
</body>
</html>
運行結(jié)果