第一個是奔跑的小熊動畫
打開網頁小熊從左邊跑到中間,然後保持勻速動畫在中間行駛
利用視覺差背景往後移動
(上代碼和圖檔)
<!DOCTYPE html>
<html >
<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>
*{
margin: 0;
padding: 0;
}
.bg1{
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 336px;
background-image: url(./img/bg1.png);
background-repeat: no-repeat;
animation: bg 5s linear infinite;
}
.bg2{
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 569px;
opacity: 0.1;
background-image: url(./img/bg2.png);
background-repeat: no-repeat; animation: bg 5s linear infinite;
}
.bg3{
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 384px;
opacity: 0.5;
background-image: url(./img/bg3.png);
background-repeat: no-repeat; animation: bg 5s linear infinite;
}
.bear{
position: absolute;
left: 0;
bottom: 40px;
width: 200px;
height: 100px;
background-image: url(./img/bear.png);
background-repeat: no-repeat;
animation: bear 1s steps(8) infinite,bear-Move 5s linear forwards;
}
/* 小熊動畫 */
@keyframes bear {
0%{
background-position: 0,0;
}
100%{
background-position: -1600px ,0;
}
}
/* 小熊奔跑動畫 */
@keyframes bear-Move {
0%{
left: 0;
}
100%{
margin-left: 50%;
transform: translateX(-100px);
}
}
/* 背景移動動畫 */
@keyframes bg {
0%{
background-position: 0,0;
}
100%{
background-position:-1200px,0 ;
}
}
</style>
</head>
<body>
<div class="bg1"></div>
<div class="bg2"></div>
<div class="bg3"></div>
<div class="bear"></div>
</body>
</html>
(素材)