CSS에서 애니메이션 속성들은 animation 단축 속성으로도 쓸 수 있고, 각각을 개별적으로 설정할 수도 있다.
애니메이션의 이름을 설정한다.
이 이름은 @keyframes
에서 정의한 이름과 일치해야 한다.
none
(기본값) | 사용자 정의 이름animation-name: bounce;
애니메이션이 한 사이클을 완료하는 데 걸리는 시간을 설정한다.
시간 단위
(s
초, ms
밀리초) | 기본값: 0s
animation-duration: 3s; /* 3초 동안 애니메이션 진행 */
애니메이션 속도의 변화 곡선(가속도와 감속도)를 설정한다.
값:
예시:
animation-timing-function: ease-in-out;
애니메이션이 시작되기 전에 대기하는 시간을 설정한다.
시간 단위
(s
, ms
) | 기본값: 0s
animation-delay: 2s; /* 2초 후에 애니메이션 시작 */
애니메이션의 반복 횟수를 설정한다.
값:
1
예시:
animation-iteration-count: infinite; /* 무한 반복 */
animation-iteration-count: 3; /* 3번 반복 */
애니메이션의 재생 방향을 설정한다.
값:
예시:
animation-direction: alternate; /* 정방향과 역방향 번갈아 반복 */
애니메이션이 시작 전과 종료 후에 어떤 스타일을 유지할지 설정한다.
animation-fill-mode: forwards; /* 애니메이션 종료 후 마지막 상태 유지 */
애니메이션의 재생과 일시 정지 상태를 설정한다.
값:
예시:
animation-play-state: paused; /* 애니메이션 일시 정지 */
모든 속성을 개별적으로 설정한 예시:
.sun {
animation-name: bounce;
animation-duration: 4s;
animation-timing-function: ease-in-out;
animation-delay: 1s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-fill-mode: both;
}
단축 속성으로 한 번에 설정한 예시:
.sun {
animation: bounce 4s ease-in-out 1s infinite alternate both;
}
html
.sun {
animation: bounce 4s ease-in-out 1s infinite alternate both;
}
css
:root {
overflow: hidden;
background-color: lightblue;
display: flex;
justify-content: center;
}
.sun {
background-color: yellow;
border-radius: 50%;
height: 100vh;
aspect-ratio: 1 / 1;
animation: 4s linear 0s infinite alternate animating-multiple-properties;
}
/* 단일 애니메이션에서 여러 속성을 애니메이션할 수 있습니다. */
@keyframes animating-multiple-properties {
from {
transform: translateY(110vh);
background-color: red;
filter: brightness(75%);
}
to {
transform: translateY(0);
background-color: orange;
/* 설정되지 않은 속성, 즉 'filter'는 기본값으로 되돌아갑니다. */
}
}