-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (58 loc) · 2.78 KB
/
script.js
File metadata and controls
66 lines (58 loc) · 2.78 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
document.addEventListener('DOMContentLoaded', () => {
/* ── Sticky Nav ─────────────────────────── */
const nav = document.getElementById('nav');
window.addEventListener('scroll', () => {
nav.classList.toggle('solid', window.scrollY > 60);
}, { passive: true });
/* ── Mobile Drawer ──────────────────────── */
const burger = document.getElementById('navBurger');
const drawer = document.getElementById('navDrawer');
const back = document.getElementById('drawerBackdrop');
const close = document.getElementById('drawerClose');
const openDrawer = () => { drawer.classList.add('open'); back.classList.add('show'); document.body.style.overflow = 'hidden'; };
const closeDrawer = () => { drawer.classList.remove('open'); back.classList.remove('show'); document.body.style.overflow = ''; };
if (burger) burger.addEventListener('click', openDrawer);
if (close) close.addEventListener('click', closeDrawer);
if (back) back.addEventListener('click', closeDrawer);
drawer?.querySelectorAll('a').forEach(a => a.addEventListener('click', closeDrawer));
/* ── Reveal on Scroll ───────────────────── */
const reveals = document.querySelectorAll('.reveal');
const io = new IntersectionObserver(entries => {
entries.forEach(e => {
if (e.isIntersecting) {
e.target.classList.add('visible');
io.unobserve(e.target);
}
});
}, { threshold: 0.1, rootMargin: '0px 0px -60px 0px' });
reveals.forEach(el => io.observe(el));
/* ── Number Count-Up ────────────────────── */
const stats = document.querySelectorAll('.istat__n[data-target]');
const counter = new IntersectionObserver(entries => {
entries.forEach(e => {
if (!e.isIntersecting) return;
const el = e.target;
const target = +el.getAttribute('data-target');
const dur = 1600;
const step = target / (dur / 16);
let cur = 0;
const tick = () => {
cur = Math.min(cur + step, target);
el.textContent = Math.round(cur).toLocaleString();
if (cur < target) requestAnimationFrame(tick);
};
requestAnimationFrame(tick);
counter.unobserve(el);
});
}, { threshold: 0.6 });
stats.forEach(el => counter.observe(el));
/* ── Parallax Hero Photo ────────────────── */
const heroPhoto = document.querySelector('.hero__photo');
if (heroPhoto) {
window.addEventListener('scroll', () => {
if (window.scrollY < window.innerHeight * 1.1) {
heroPhoto.style.transform = `scale(1.07) translateY(${window.scrollY * 0.08}px)`;
}
}, { passive: true });
}
});