Skip to content

Commit c034c20

Browse files
committed
[style] 배경
1 parent ba76040 commit c034c20

File tree

5 files changed

+89
-2
lines changed

5 files changed

+89
-2
lines changed

public/1Stars.png

28.5 KB
Loading

public/2Stars.png

30.8 KB
Loading

src/app/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import StarMain from '@/domains/shared/components/3d/StarMain';
2+
13
export default function Home() {
24
return (
35
<div className="page-layout max-w-full">
4-
<h1>메인페이지</h1>
6+
<StarMain />
57
</div>
68
);
79
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
'use client';
2+
3+
import Image from 'next/image';
4+
import foreStar from '../../../../../public/1Stars.png';
5+
import backStar from '../../../../../public/2Stars.png';
6+
import { useEffect, useRef } from 'react';
7+
import gsap from 'gsap';
8+
9+
function StarMain() {
10+
const background = useRef<HTMLDivElement>(null);
11+
const foreground = useRef<HTMLDivElement>(null);
12+
const mouse = useRef({ x: 0, y: 0 });
13+
const rafId = useRef<number | null>(null);
14+
15+
useEffect(() => {
16+
if (!background.current || !foreground.current) return;
17+
18+
const bgX = gsap.quickSetter(background.current, 'x', 'px');
19+
const bgY = gsap.quickSetter(background.current, 'x', 'px');
20+
const bgRotate = gsap.quickSetter(background.current, 'rotate', 'deg');
21+
22+
const fgX = gsap.quickSetter(foreground.current, 'x', 'px');
23+
const fgY = gsap.quickSetter(foreground.current, 'y', 'px');
24+
const fgRotate = gsap.quickSetter(foreground.current, 'rotate', 'deg');
25+
26+
const update = () => {
27+
const { x, y } = mouse.current;
28+
29+
bgX(x * -10);
30+
bgY(y * -10);
31+
bgRotate(x * -5);
32+
33+
fgX(x * 20);
34+
fgY(y * 20);
35+
fgRotate(y * 5);
36+
37+
rafId.current = requestAnimationFrame(update);
38+
};
39+
40+
const handleMouseMove = (e: MouseEvent) => {
41+
// 화면 중앙 기준으로 얼마나 벗어났는지 (-1 ~ 1 범위)
42+
const x = (e.clientX / window.innerWidth - 0.5) * 2;
43+
const y = (e.clientY / window.innerHeight - 0.5) * 2;
44+
mouse.current = { x, y };
45+
};
46+
47+
const handleTouchMove = (e: TouchEvent) => {
48+
const touch = e.touches[0];
49+
const x = (touch.clientX / window.innerWidth - 0.5) * 2;
50+
const y = (touch.clientY / window.innerHeight - 0.5) * 2;
51+
mouse.current = { x, y };
52+
};
53+
54+
window.addEventListener('mousemove', handleMouseMove);
55+
window.addEventListener('touchmove', handleTouchMove);
56+
rafId.current = requestAnimationFrame(update);
57+
58+
return () => {
59+
window.removeEventListener('mousemove', handleMouseMove);
60+
window.removeEventListener('touchmove', handleTouchMove);
61+
if (rafId.current) cancelAnimationFrame(rafId.current);
62+
};
63+
}, []);
64+
65+
return (
66+
<div>
67+
<div className="absolute top-0 left-0 w-full h-full overflow-hidden pointer-events-none">
68+
<div
69+
ref={background}
70+
className="absolute w-screen h-screen top-0 left-0 will-change-transform"
71+
>
72+
<Image src={foreStar} alt="앞쪽 별" fill className="object-cover object-center" />
73+
</div>
74+
<div
75+
ref={foreground}
76+
className="absolute w-screen h-screen top-0 left-0 will-change-transform"
77+
>
78+
<Image src={backStar} alt="뒤쪽 별" fill className="object-cover object-center" />
79+
</div>
80+
</div>
81+
</div>
82+
);
83+
}
84+
85+
export default StarMain;

src/shared/components/footer/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Github from './Github';
22

33
function Footer() {
44
return (
5-
<footer className="w-full bg-primary flex items-center justify-between p-[12px] font-serif font-light shadow-footer">
5+
<footer className="w-full bg-primary flex items-center justify-between p-[12px] font-serif font-light shadow-footer z-10">
66
<div className="flex flex-col gap-1">
77
<p className="text-sm md:text-base">Cocktail Discovery Service, SSOUL </p>
88
<div className="flex flex-col sm:flex-row gap-0.5 sm:gap-2 text-sm md:text-base">

0 commit comments

Comments
 (0)