Skip to content

Commit 3b6a1bb

Browse files
committed
Refactor: 로딩 애니메이션을 animation으로 수정
1 parent 198569d commit 3b6a1bb

2 files changed

Lines changed: 22 additions & 27 deletions

File tree

src/components/Loading/index.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
import { useEffect, useState } from 'react';
21
import { Dot, DotBox, LoadingWrapper } from './styles';
32

43
const Loading: React.FC = () => {
5-
const [dotIndex, setDotIndex] = useState(0);
6-
7-
useEffect(() => {
8-
const interval = setInterval(() => {
9-
setDotIndex((prev) => prev + 1);
10-
}, 300); // 0.3초마다 업데이트
11-
12-
// 컴포넌트가 언마운트되면 interval을 정리
13-
return () => clearInterval(interval);
14-
}, []);
15-
164
return (
175
<LoadingWrapper>
186
<DotBox>
19-
<Dot $index={0} $dotIndex={dotIndex} />
20-
<Dot $index={1} $dotIndex={dotIndex} />
21-
<Dot $index={2} $dotIndex={dotIndex} />
7+
<Dot $index={0} />
8+
<Dot $index={1} />
9+
<Dot $index={2} />
2210
</DotBox>
2311
</LoadingWrapper>
2412
);

src/components/Loading/styles.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
import styled, { css } from 'styled-components';
1+
import styled, { keyframes } from 'styled-components';
2+
3+
// 점이 활성화될 때의 애니메이션 (Y축으로 움직임)
4+
const bounce = keyframes`
5+
0%, 100% {
6+
transform: translateY(0);
7+
opacity: 0.5;
8+
}
9+
50% {
10+
transform: translateY(-2px);
11+
opacity: 1;
12+
}
13+
`;
214

315
export const LoadingWrapper = styled.div`
416
position: fixed;
@@ -18,20 +30,15 @@ export const DotBox = styled.div`
1830
margin: auto;
1931
`;
2032

21-
export const Dot = styled.hr<{ $index: number; $dotIndex: number }>`
22-
width: 7px;
23-
height: 7px;
33+
export const Dot = styled.hr<{ $index: number }>`
34+
width: 8px;
35+
height: 8px;
2436
z-index: 200;
2537
border-radius: 50%;
2638
border: none;
2739
background-color: ${({ theme }) => theme.colors.gray2};
28-
transition:
29-
opacity 0.3s,
30-
transform 0.3s;
3140
32-
// 점이 활성화되었을 때의 스타일
33-
${({ $index, $dotIndex }) => css`
34-
opacity: ${$dotIndex % 3 === $index ? 1 : 0.5};
35-
transform: translateY(${$dotIndex % 3 === $index ? -1 : 0}px);
36-
`}
41+
// 각 점에 대해 딜레이를 적용하여 순차적으로 애니메이션을 시작
42+
animation: ${bounce} 0.6s ease-in-out infinite;
43+
animation-delay: ${({ $index }) => $index * 0.2}s;
3744
`;

0 commit comments

Comments
 (0)