-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
58 lines (55 loc) · 1.89 KB
/
script.js
File metadata and controls
58 lines (55 loc) · 1.89 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
// Reveal-on-scroll using IntersectionObserver
(() => {
const reveal = () => {
const els = document.querySelectorAll('.reveal');
if (!('IntersectionObserver' in window) || !els.length) {
els.forEach(el => el.classList.add('in'));
return;
}
const io = new IntersectionObserver((entries) => {
entries.forEach(e => {
if (e.isIntersecting) {
e.target.classList.add('in');
io.unobserve(e.target);
}
});
}, { threshold: 0.12, rootMargin: '0px 0px -60px 0px' });
els.forEach(el => io.observe(el));
};
// Mobile nav toggle
const navToggle = () => {
const toggle = document.querySelector('.nav-toggle');
const links = document.querySelector('.nav-links');
if (!toggle || !links) return;
toggle.addEventListener('click', () => {
links.classList.toggle('open');
const open = links.classList.contains('open');
toggle.setAttribute('aria-expanded', open ? 'true' : 'false');
});
// Close when a link is clicked (mobile)
links.addEventListener('click', (e) => {
if (e.target.tagName === 'A') links.classList.remove('open');
});
};
// Subtle parallax tilt on featured cards (desktop only)
const tilt = () => {
if (window.matchMedia('(hover: none)').matches) return;
const cards = document.querySelectorAll('.featured-card');
cards.forEach(card => {
card.addEventListener('mousemove', (e) => {
const r = card.getBoundingClientRect();
const x = (e.clientX - r.left) / r.width - 0.5;
const y = (e.clientY - r.top) / r.height - 0.5;
card.style.transform = `translateY(-4px) rotateX(${y * -2}deg) rotateY(${x * 3}deg)`;
});
card.addEventListener('mouseleave', () => {
card.style.transform = '';
});
});
};
document.addEventListener('DOMContentLoaded', () => {
reveal();
navToggle();
tilt();
});
})();