transition과 달리 키프레임 지정이 가능하며, 재생 횟수, 진행 방향, 정지 등 다양한 기능 제공
animation 효과를 사용하기 위한 규칙
from: 시작 지점
to: 끝 지점
percentage: 중간 단계 지점@keyframes animation-name { from { /* 효과 */ } 50% { /* 효과 */ } to { /* 효과 */ } }
animation-naem와 함께 필수로 선언되어야 하는 속성으로
애니메이션의 진행 시간 지정animation-name: fade; animation-duration: 2s;
애니메이션 재생 횟수
animation-iteration-count: 3; animation-iteration-count: infinite;
애니메이션 진행 방향
/* 기본값, 순방향 진행 */ animation-direction: normal; /* 역방향 진행 */ animation-direction: reverse; /* 순방향 - 역방향 반복 > 리와인드. 반복 횟수 여러번 일 경우 사용 */ animation-direction: alternate;
애니메이션 실행 전 지연 시간 적용
animation-delay: 1s;
애니메이션 진행 속도의 변화
/* 같은 속도로 진행 */ animation-timing-function: linear; /* 속도가 빨라지다가 느려진다 - 공 튀기기 */ animation-timing-function: ease-in-out;
애니메이션 실행 전 후 효과 표시 여부 지정
/* 애니메이션의 마지막 상태 그대로 시작 */ animation-fill-mode: forwards; /* 애니메이션의 마지막 상태를 가져와서 시작할 때 초기값으로 돌아온다 */ animation-fill-mode: backwards; /* 애니메이션의 시작과 끝을 그대로 유지 */ animation-fill-mode: none; /* forwards와 backwards 둘 다 적용 */ animation-fill-mode: both;
애니메이션 재생 상태 제어
/* 기본값 - 진행된 상태 */ animation-play-state: running; /* 정지된 상태 */ animation-play-state: paused;
단축 표기
animation-name과animation-duration은 필수속성
앞에 오는초 속성이animation-duration으로 적용된다.animation: fade 2s infinite 1s linear both;
@keyframes shrink { 0%, 100% { width: 100%; } 50% { width: 50%; } } .case-02 .target-animation{ animation: shrink 2s infinite ease-in-out both; animation-play-state: paused; }
요소의 회전, 크기, 기울이기, 이동효과 지정
키프레임 지정 불가능
전이되는 과정 구현하는 속성
필수 속성transition-property: all; transition-property: background;
전이가 진행되는 시간
필수 속성transition-duration: 3s;
전이되기 전 지연 시간
transition-delay: 2s'
전이 진행 속도 변화
transition-timing-function: ease-in-out; /* n개의 정지 지점에 따라 전환 표시 */ /* jump-term: start, end, none - 전환 시작점 설정*/ transition-timing-function: steps(n, jump-term); /* 그래프로 속도 변화 지정 */ transition-timing-function: cubic-bezier(0,1.59,1,-0.75);
단축 표기
transition: all 3s ease-in 2s;
background: var(--pastel-lavender); transition: all 200ms; &:hover { background: var(--pastel-orange); border-radius: 50%; rotate: 2turn;transition: rotate 500ms;
투명도 조절
/* 기본값 - 투명도 0 */ opaciry: 1; /* 투명도 100 */ opacity: 0;
이동
transform: translateX(20px); transform: translateY(10px); translate 20px 10px
회전
rotate: 1turn; rotate: 180deg;
확대
scale: 1 1;
원근감 - 뒤집기 효과에 사용
통상적으로 400px 사용transform: perspective(400px) rotateY(360deg);
translate와rotate함께 사용transform: translateX(0%) rotate(0deg); transform: translateX(-15px) rotate(-5deg);
box-shadow: 0 0 10px light-dark(rgb(0 0 0 /0.6), rgb(255 255 255 /0.6));
요소 뒤에 회전하는
background-image로gradient를 준다@keyframes rotate { from { --rotation: 0deg; } to { --rotation: 360deg; } } @property --rotation { syntax: "<angle>"; inherits: false; initial-value: 0deg; } .case-10 .target-animation { width: 150px; aspect-ratio: 1/1; position: relative; &::before, &::after{ --rotation: 0deg; box-sizing: content-box; content: ""; position: absolute; width: 100%; height: 100%; inset: 50%; translate: -50% -50%; background: conic-gradient(from var(--rotation), red, orange, yellow, green, blue, purple, red); padding: 1px; z-index: -1; border-radius: 8px; animation: rotate 1s infinite linear; animation-play-state: paused; } &::before{ filter: blur(15px); } }