-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (67 loc) · 2.51 KB
/
script.js
File metadata and controls
76 lines (67 loc) · 2.51 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
/* ============================================================
MILK & HONEY CREATIVE STUDIO — Interactions
============================================================ */
document.addEventListener('DOMContentLoaded', function () {
/* ── Sticky header scroll state ── */
const header = document.getElementById('site-header');
if (header) {
const onScroll = () => {
header.classList.toggle('scrolled', window.scrollY > 40);
};
window.addEventListener('scroll', onScroll, { passive: true });
onScroll();
}
/* ── Mobile hamburger menu ── */
const toggle = document.getElementById('menu-toggle');
const nav = document.getElementById('main-nav');
if (toggle && nav) {
toggle.addEventListener('click', () => {
const isOpen = nav.classList.toggle('open');
toggle.classList.toggle('open', isOpen);
toggle.setAttribute('aria-expanded', String(isOpen));
document.body.style.overflow = isOpen ? 'hidden' : '';
});
// Close menu when a link is clicked
nav.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
nav.classList.remove('open');
toggle.classList.remove('open');
toggle.setAttribute('aria-expanded', 'false');
document.body.style.overflow = '';
});
});
// Close on Escape key
document.addEventListener('keydown', e => {
if (e.key === 'Escape' && nav.classList.contains('open')) {
nav.classList.remove('open');
toggle.classList.remove('open');
toggle.setAttribute('aria-expanded', 'false');
document.body.style.overflow = '';
}
});
}
/* ── Scroll reveal animation ── */
const reveals = document.querySelectorAll('.reveal');
if (reveals.length > 0) {
const observer = new IntersectionObserver(
entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('revealed');
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.12, rootMargin: '0px 0px -40px 0px' }
);
reveals.forEach(el => observer.observe(el));
}
/* ── Active nav link ── */
const currentPath = window.location.pathname.split('/').pop() || 'index.html';
document.querySelectorAll('.mhc-nav a:not(.mhc-cta)').forEach(link => {
const href = link.getAttribute('href');
if (href === currentPath || (currentPath === '' && href === 'index.html')) {
link.style.color = 'var(--gold)';
}
});
});