-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (59 loc) · 2.56 KB
/
Copy pathscript.js
File metadata and controls
66 lines (59 loc) · 2.56 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
const header = document.querySelector('.site-header');
const menuButton = document.querySelector('.menu-toggle');
const mobileMenu = document.querySelector('.mobile-menu');
const modal = document.querySelector('.project-modal');
window.addEventListener('scroll', () => {
header.classList.toggle('scrolled', window.scrollY > 40);
}, { passive: true });
menuButton.addEventListener('click', () => {
const open = mobileMenu.classList.toggle('open');
menuButton.setAttribute('aria-expanded', String(open));
menuButton.setAttribute('aria-label', open ? '메뉴 닫기' : '메뉴 열기');
mobileMenu.setAttribute('aria-hidden', String(!open));
document.body.style.overflow = open ? 'hidden' : '';
});
mobileMenu.querySelectorAll('a').forEach(link => link.addEventListener('click', () => {
mobileMenu.classList.remove('open');
menuButton.setAttribute('aria-expanded', 'false');
mobileMenu.setAttribute('aria-hidden', 'true');
document.body.style.overflow = '';
}));
const revealObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
revealObserver.unobserve(entry.target);
}
});
}, { threshold: 0.14 });
document.querySelectorAll('.reveal').forEach(el => revealObserver.observe(el));
const countObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (!entry.isIntersecting) return;
const el = entry.target;
const target = Number(el.dataset.count);
const start = performance.now();
const tick = now => {
const progress = Math.min((now - start) / 1200, 1);
el.textContent = Math.round(target * (1 - Math.pow(1 - progress, 3)));
if (progress < 1) requestAnimationFrame(tick);
};
requestAnimationFrame(tick);
countObserver.unobserve(el);
});
}, { threshold: 0.7 });
document.querySelectorAll('[data-count]').forEach(el => countObserver.observe(el));
document.querySelectorAll('[data-project]').forEach(button => {
button.addEventListener('click', () => {
modal.querySelector('h2').textContent = button.dataset.project;
modal.showModal();
});
});
modal.querySelector('.modal-close').addEventListener('click', () => modal.close());
modal.addEventListener('click', event => {
const box = modal.getBoundingClientRect();
if (event.clientX < box.left || event.clientX > box.right || event.clientY < box.top || event.clientY > box.bottom) modal.close();
});
document.querySelector('.play-button').addEventListener('click', () => {
document.querySelector('#works').scrollIntoView({ behavior: 'smooth' });
});