代碼
提交代碼
<!DOCTYPE html>
<html lang="en">
<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;
}
.animate {
width: 100px;
height: 100px;
/* 使用預(yù)先定義好的動畫,過渡動畫 */
animation: change-color 2s linear infinite alternate;
}
/* 定義動畫 */
@keyframes change-color {
from { background: yellow }
to { background: green }
}
</style>
</head>
<body>
<div class="animate"></div>
</body>
</html>
運(yùn)行結(jié)果