반응형
CSS animation을 활용해서 카운트다운을 구현해 보겠습니다.
구현 코드
HTML
카운터로 표시될 만큼의 숫자를 추가합니다.
<div class="contents">
<div class="count">
<div class="num">1</div>
<div class="num">2</div>
<div class="num">3</div>
<div class="num">Go</div>
</div>
</div>
CSS
애니메이션에서 delay를 통해 순차적으로 작동하도록 구현합니다.
/* count */
.count {
height: 50px;
width: 50px;
position: relative;
margin: auto;
overflow: hidden;
}
.count .num {
height: 40px;
position: absolute;
bottom: -5px;
left: 50%;
transform-origin: bottom;
transform: translateX(-50%) rotate(180deg);
font-size: 1.5rem;
}
.count .num:nth-child(1) {
animation: spin 2s cubic-bezier(0.075, 0.82, 0.165, 1) forwards;
}
.count .num:nth-child(2) {
animation: spin 2s 2s cubic-bezier(0.075, 0.82, 0.165, 1) forwards;
}
.count .num:nth-child(3) {
animation: spin 2s 4s cubic-bezier(0.075, 0.82, 0.165, 1) forwards;
}
.count .num:nth-child(4) {
animation: spin 2s 6s cubic-bezier(0.075, 0.82, 0.165, 1) forwards;
}
@keyframes spin {
0% {
transform: translateX(-50%) rotate(180deg);
}
30% {
transform: translateX(-50%) rotate(-10deg);
}
60% {
transform: translateX(-50%) rotate(10deg);
}
100% {
transform: translateX(-50%) rotate(-180deg);
}
}
이상으로 CSS animation을 활용하여 카운트다운을 구현하는 방법을 살펴보았습니다.
728x90
반응형
'프론트엔드 > CSS' 카테고리의 다른 글
Grid (0) | 2022.12.29 |
---|---|
Flex (0) | 2022.12.29 |
Viewport (0) | 2022.12.29 |
Media queries (0) | 2022.12.29 |
CSS 컴포넌트 - 토글버튼 (0) | 2022.12.20 |