-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
494 lines (421 loc) · 13.3 KB
/
Copy pathscript.js
File metadata and controls
494 lines (421 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
// GSAP 등록
gsap.registerPlugin(ScrollTrigger);
// 텍스트 글자별 분리 함수
function splitTextIntoChars(element) {
const text = element.textContent;
element.innerHTML = '';
const chars = text.split('');
chars.forEach(char => {
const span = document.createElement('span');
span.textContent = char === ' ' ? '\u00A0' : char;
span.style.display = 'inline-block';
element.appendChild(span);
});
return element.querySelectorAll('span');
}
// 페이지 로드 애니메이션
window.addEventListener('load', () => {
const preloader = document.querySelector('.preloader');
const heroLines = document.querySelectorAll('.hero-line');
const heroSubtitle = document.querySelector('.hero-subtitle');
setTimeout(() => {
gsap.to(preloader, {
opacity: 0,
duration: 0.5,
onComplete: () => {
preloader.style.display = 'none';
// 각 라인의 텍스트를 글자별로 분리
heroLines.forEach((line, lineIndex) => {
const chars = splitTextIntoChars(line);
// 세 번째 라인에 그라데이션 클래스 추가
if (lineIndex === 2) {
line.classList.add('gradient-text');
}
// 글자별 애니메이션
gsap.fromTo(chars,
{
opacity: 0,
y: 100,
rotationX: -90
},
{
opacity: 1,
y: 0,
rotationX: 0,
duration: 0.8,
stagger: 0.03,
ease: 'back.out(1.5)',
delay: lineIndex * 0.3
}
);
});
// 서브타이틀 애니메이션
gsap.to(heroSubtitle, {
opacity: 1,
y: 0,
duration: 1,
delay: 1.5,
ease: 'power2.out'
});
}
});
}, 1500);
});
// 커스텀 커서
const cursor = document.querySelector('.cursor');
const cursorFollower = document.querySelector('.cursor-follower');
let mouseX = 0, mouseY = 0;
let cursorX = 0, cursorY = 0;
let followerX = 0, followerY = 0;
document.addEventListener('mousemove', (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
});
function animateCursor() {
cursorX += (mouseX - cursorX) ;
cursorY += (mouseY - cursorY) ;
followerX += (mouseX - followerX) * 0.15;
followerY += (mouseY - followerY) * 0.15;
cursor.style.transform = `translate3d(${cursorX}px, ${cursorY}px, 0)`;
cursorFollower.style.transform = `translate3d(${followerX - 10}px, ${followerY - 10}px, 0)`;
requestAnimationFrame(animateCursor);
}
animateCursor();
// 링크 호버 효과
const links = document.querySelectorAll('button, .nav-toggle');
links.forEach(link => {
link.addEventListener('mouseenter', () => {
document.body.classList.add('cursor-hover');
});
link.addEventListener('mouseleave', () => {
document.body.classList.remove('cursor-hover');
});
});
// 스크롤 프로그레스 바
const scrollProgress = document.querySelector('.scroll-progress');
window.addEventListener('scroll', () => {
const scrollTop = window.pageYOffset;
const docHeight = document.documentElement.scrollHeight - window.innerHeight;
const scrollPercent = (scrollTop / docHeight) * 100;
scrollProgress.style.width = scrollPercent + '%';
});
// 네비게이션 스크롤 효과
const nav = document.querySelector('.nav');
let lastScroll = 0;
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll > 100) {
nav.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.05)';
} else {
nav.style.boxShadow = 'none';
}
lastScroll = currentScroll;
});
// About 섹션 카운터 애니메이션 (수정)
const statNumbers = document.querySelectorAll('.stat-number');
statNumbers.forEach(stat => {
const target = parseInt(stat.getAttribute('data-target'));
ScrollTrigger.create({
trigger: stat,
start: 'top 80%',
onEnter: () => {
let current = 0;
const increment = target / 50;
const timer = setInterval(() => {
current += increment;
if (current >= target) {
stat.textContent = target; // + 없이 숫자만
clearInterval(timer);
} else {
stat.textContent = Math.floor(current);
}
}, 30);
}
});
});
// About 섹션 애니메이션 (새로 추가)
gsap.from('.image-wrapper', {
scrollTrigger: {
trigger: '.about',
start: 'top 70%',
toggleActions: 'play none none reverse'
},
scale: 0.8,
opacity: 0,
duration: 1.2,
ease: 'back.out(1.3)'
});
gsap.from('.about-description', {
scrollTrigger: {
trigger: '.about-description',
start: 'top 80%',
toggleActions: 'play none none reverse'
},
x: -50,
opacity: 0,
duration: 1,
ease: 'power2.out'
});
gsap.from('.about-description2 .stat-item', {
scrollTrigger: {
trigger: '.about-description2',
start: 'top 85%',
toggleActions: 'play none none reverse'
},
y: 30,
opacity: 0,
duration: 0.8,
stagger: 0.15,
ease: 'power2.out'
});
gsap.from('.about-stats .stat-item', {
scrollTrigger: {
trigger: '.about-stats',
start: 'top 85%',
toggleActions: 'play none none reverse'
},
y: 30,
opacity: 0,
duration: 0.8,
stagger: 0.15,
ease: 'power2.out'
});
gsap.from('.info-item', {
scrollTrigger: {
trigger: '.about-info',
start: 'top 80%',
toggleActions: 'play none none reverse'
},
x: -50,
opacity: 0,
duration: 0.8,
stagger: 0.1,
ease: 'power2.out'
});
// Experience 섹션 타임라인 애니메이션 (새로 추가)
gsap.utils.toArray('.timeline-item').forEach((item, index) => {
gsap.from(item, {
scrollTrigger: {
trigger: item,
start: 'top 85%',
toggleActions: 'play none none reverse'
},
y: -50,
opacity: 0,
duration: 0.8,
delay: index * 0.1,
ease: 'power2.out'
});
});
// Timeline 선 애니메이션
gsap.utils.toArray('.timeline').forEach(timeline => {
gsap.from(timeline.querySelector('::before'), {
scrollTrigger: {
trigger: timeline,
start: 'top 80%',
toggleActions: 'play none none reverse'
},
scaleY: 0,
transformOrigin: 'top',
duration: 1.5,
ease: 'power2.out'
});
});
// 섹션 페이드인 애니메이션
gsap.utils.toArray('section').forEach(section => {
gsap.from(section.querySelectorAll('.section-title, .section-number'), {
scrollTrigger: {
trigger: section,
start: 'top 80%',
toggleActions: 'play none none reverse'
},
y: 50,
opacity: 0,
duration: 1,
stagger: 0.1
});
});
// 프로젝트 패럴랙스 효과 (기존 코드를 찾아서 이것으로 교체)
gsap.utils.toArray('.project-item').forEach((project, index) => {
const image = project.querySelector('.project-image-wrapper');
const info = project.querySelector('.project-info');
gsap.from(image, {
scrollTrigger: {
trigger: project,
start: 'top 80%',
end: 'bottom 100%',
scrub: 1
},
opacity: 0
});
gsap.from(info.children, {
scrollTrigger: {
trigger: project,
start: 'top 60%',
toggleActions: 'play none none reverse'
},
y: 50,
opacity: 0,
duration: 1,
stagger: 0.15
});
});
// 스킬바 애니메이션
const skillBars = document.querySelectorAll('.skill-progress');
skillBars.forEach(bar => {
const progress = bar.getAttribute('data-progress');
ScrollTrigger.create({
trigger: bar,
start: 'top 85%',
onEnter: () => {
gsap.to(bar, {
width: progress + '%',
duration: 1.5,
ease: 'power2.out'
});
}
});
});
// About 이미지 패럴랙스
gsap.to('.image-placeholder', {
scrollTrigger: {
trigger: '.about',
start: 'top bottom',
end: 'bottom top',
scrub: 1
},
y: -50
});
// 내비/섹션 앵커만 부드러운 스크롤
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
const href = this.getAttribute('href');
// #about, #projects 같은 내부 앵커일 때만 기본 동작 막기
if (href.startsWith('#') && href.length > 1) {
e.preventDefault();
const target = document.querySelector(href);
if (target) {
window.scrollTo({
top: target.offsetTop - 80,
behavior: 'smooth'
});
}
}
});
});
// 모바일 네비게이션 토글
const navToggle = document.querySelector('.nav-toggle');
const navMenu = document.querySelector('.nav-menu');
if (navToggle) {
navToggle.addEventListener('click', () => {
navMenu.classList.toggle('active');
navToggle.classList.toggle('active');
});
}
// 스크롤 인디케이터 페이드아웃
gsap.to('.hero-scroll', {
scrollTrigger: {
trigger: '.hero',
start: 'top top',
end: 'bottom top',
scrub: 1
},
opacity: 0,
y: 20
});
// Contact 섹션 애니메이션
gsap.from('.contact-email', {
scrollTrigger: {
trigger: '.contact',
start: 'top 70%',
toggleActions: 'play none none reverse'
},
scale: 0.8,
opacity: 0,
duration: 1,
ease: 'back.out(1.7)'
});
gsap.from('.social-link', {
scrollTrigger: {
trigger: '.contact-social',
start: 'top 85%',
toggleActions: 'play none none reverse'
},
y: 30,
opacity: 0,
duration: 0.8,
stagger: 0.2
});
// index.html에서만: 쿼리 파라미터를 보고 Projects 섹션으로 스크롤
window.addEventListener('load', () => {
const params = new URLSearchParams(window.location.search);
const from = params.get('from');
if (from === 'projects') {
const projectsSection = document.getElementById('projects');
if (projectsSection) {
window.scrollTo({
top: projectsSection.offsetTop - 80,
behavior: 'smooth'
});
}
// 주소창에서 ?from=projects 제거 (새로고침 시 인트로부터 시작)
if (window.history && window.history.replaceState) {
const cleanUrl = window.location.pathname; // 예: /index.html
window.history.replaceState({}, '', cleanUrl);
}
}
});
window.addEventListener('load', () => {
const params = new URLSearchParams(window.location.search);
const from = params.get('from');
let targetId = null;
if (from === 'projects') targetId = 'projects';
if (from === 'contact') targetId = 'contact';
if (targetId) {
const target = document.getElementById(targetId);
if (target) {
window.scrollTo({
top: target.offsetTop - 80,
behavior: 'smooth'
});
}
// 새로고침 시 인트로부터 보이도록 쿼리 제거
if (window.history && window.history.replaceState) {
const cleanUrl = window.location.pathname;
window.history.replaceState({}, '', cleanUrl);
}
}
});
// Contact 텍스트 페이드인
gsap.from('.contact-text', {
scrollTrigger: {
trigger: '.contact-text',
start: 'top 85%',
toggleActions: 'play none none reverse'
},
opacity: 0,
y: 20,
duration: 0.9,
ease: 'power2.out'
});
// Timeline 토글 기능
document.querySelectorAll('.timeline-content').forEach(content => {
content.addEventListener('click', function(e) {
const item = this.closest('.timeline-item');
const detailText = item.querySelector('.timeline-text-detail');
const summary = item.querySelector('.timeline-text-summary');
const toggleText = item.querySelector('.toggle-text');
const toggleButton = item.querySelector('.timeline-toggle');
if (detailText.style.display === 'none' || !detailText.style.display) {
detailText.style.display = 'block';
summary.style.display = 'none';
toggleText.textContent = '접기';
toggleButton.classList.add('active');
} else {
detailText.style.display = 'none';
summary.style.display = 'inline';
toggleText.textContent = '상세보기';
toggleButton.classList.remove('active');
}
});
});