고양이가 걸어가는 애니메이션 만들기

더욱 간단하게 만드는 방법도 있다.(날라가는 새)

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>고양이가 움직이는 애니메이션</title>
<link rel="stylesheet" href="css/cat.css">
</head>
<body>
<div class="catArea">
<div class="cat"></div>
</div>
</body>
</html>
body {background:#626262;}
.catArea {
border:3px solid yellow; width:209px;
position:fixed; left:0; top:200px;
animation: toRight 15s infinite both linear;
}
@keyframes toRight {
from {left: 0;}
to {left: 100vw;}
}
.cat {
background-image: url( "../images/cat.jpg" );
width:209px; height:436px;
border:3px dashed red;
animation: cat 1s infinite steps(8) ;
}
@keyframes cat {
100% {background-position: 1672px;}
}

background-image: url( "../images/cat.jpg" )에서 ".."은 백그라운드 이미지를 현재 파일 위치에서 한 단계 위로 가서 images 폴더 안의 cat.jpg 파일을 찾는 것을 의미한다.animation: cat 1s infinite steps(8)은 애니메이션이 8단계로 나누어져서 진행된다는 의미다. 즉, 애니메이션이 부드럽게 진행되지 않고, 8개의 정해진 단계로 끊어져서 전환된다.