@keyframes example {
0% {
background-color: red;
transform: translateX(0);
}
100% {
background-color: blue;
transform: translateX(100px);
}
}
@keyframes example { ... }
0% (시작 상태):
background-color: red; transform: translateX(0); 100% (끝 상태):
background-color: blue; transform: translateX(100px); 중간 상태를 더 추가하고 싶다면 0%와 100% 사이에 25%, 50%, 75%와 같이 키프레임을 추가할 수 있어요.
.element {
width: 100px;
height: 100px;
animation: example 2s infinite;
}
.element { ... }
width: 100px;와 height: 100px;
animation: example 2s infinite;
시작:
.element에 빨간색 배경과 원래 위치에서 시작합니다.2초 동안 진행:
반복:
이 예제 코드를 통해 CSS의 @keyframes를 사용하여 간단한 애니메이션을 어떻게 정의하고 적용하는지, 그리고 애니메이션의 각 단계를 어떻게 설정하는지 이해할 수 있어요.