애니메이션 속성
요소에 움직임을 지정하고 프레임별 스타일을 지정하여 애니메이션 효과를 주는 속성
•
애니메이션 속성의 종류
•
기본 예시코드
•
애니메이션 속성 응용
애니메이션 속성의 종류
속성 | 설명 | 기본 예시 코드 |
animation | 애니메이션을 적용할 요소의 속성을 설정합니다. | animation: name duration timing-function delay iteration-count direction; |
animation-name | 애니메이션의 이름을 정의합니다. | animation-name: slide; |
animation-duration | 애니메이션의 지속 시간을 설정합니다. | animation-duration: 2s; |
animation-timing-function | 애니메이션의 속도 곡선을 설정합니다. | animation-timing-function: ease-in; |
animation-delay | 애니메이션 시작 전 지연 시간을 설정합니다. | animation-delay: 1s; |
animation-iteration-count | 애니메이션의 반복 횟수를 설정합니다. | animation-iteration-count: infinite; |
animation-direction | 애니메이션의 진행 방향을 설정합니다. | animation-direction: alternate; |
animation-fill-mode | 애니메이션 종료 후 요소의 스타일을 설정합니다. | animation-fill-mode: forwards; |
기본 예시 코드
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>애니메이션 속성 예시</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
text-align: center;
padding: 50px;
background-color: #f0f0f0;
}
/* 애니메이션 정의 */
@keyframes slide {
0% { transform: translateX(0); }
100% { transform: translateX(100px); }
}
/* 애니메이션 적용 */
.animation-example {
width: 150px;
height: 150px;
background-color: lightcoral;
margin: 20px auto;
display: inline-block;
animation: slide 2s ease-in-out 1s infinite alternate;
}
</style>
</head>
<body>
<div class="animation-example"></div>
</body>
</html>
HTML
복사
이 코드는 @keyframes 규칙을 사용하여 slide 애니메이션을 정의하고, 이를 .animation-example 클래스에 적용합니다. 애니메이션의 이름, 지속 시간, 타이밍 함수, 지연 시간, 반복 횟수 및 방향을 설정하여 요소의 움직임을 제어합니다.






