代碼
提交代碼
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>動畫實戰(zhàn)</title>
<style>
/* 清除瀏覽器默認邊距 */
* { padding: 0; margin: 0; }
body {
/* 這段代碼是為了居中顯示,不是重點,看不懂的話可以無視 */
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
/* 添加背景圖 */
background: url(http://img.mukewang.com/wiki/5eda029f08f198f513660768.jpg) center / cover;
}
.animate {
width: 130px;
height: 130px;
background: url(http://img.mukewang.com/wiki/5eda0279091a541906500260.jpg);
/* 動畫: 動畫名(loading) 時長(0.6秒) 運行方式(step-end) 動畫次數(shù)(無限) */
animation: loading .6s step-end infinite;
}
/* 定義動畫:動畫名(loading) */
@keyframes loading {
from { background-position: 0 0 } /* 第一個數(shù)字代表x軸坐標,第二個數(shù)字代表y軸坐標 */
10% { background-position: -130px 0 } /* x坐標:-130 y坐標:0 */
20% { background-position: -260px 0 } /* x坐標:-260 y坐標:0 */
30% { background-position: -390px 0 } /* x坐標:-390 y坐標:0 */
40% { background-position: -520px 0 } /* x坐標:-520 y坐標:0 */
50% { background-position: 0 -130px } /* x坐標:0 y坐標:-130 */
60% { background-position: -130px -130px } /* x坐標:-130 y坐標:-130 */
70% { background-position: -260px -130px } /* x坐標:-260 y坐標:-130 */
80% { background-position: -390px -130px } /* x坐標:-390 y坐標:-130 */
90% { background-position: -520px -130px } /* x坐標:-520 y坐標:-130 */
to { background-position: 0 } /* 最后一幀不顯示,可以隨便寫 */
}
</style>
</head>
<body>
<div class="animate"></div>
</body>
</html>
運行結(jié)果