-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
89 lines (80 loc) · 3.09 KB
/
Copy pathscript.js
File metadata and controls
89 lines (80 loc) · 3.09 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
/* ============================================
CODY LANIER — PORTFOLIO INTERACTIONS
Scroll reveal, nav state, mobile menu
============================================ */
(function () {
'use strict';
// --- Scroll Reveal ---
const revealElements = document.querySelectorAll('.reveal');
const revealObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry, i) => {
if (entry.isIntersecting) {
// Stagger siblings that enter at roughly the same time
const delay = i * 80;
setTimeout(() => {
entry.target.classList.add('visible');
}, delay);
revealObserver.unobserve(entry.target);
}
});
},
{ threshold: 0.1, rootMargin: '0px 0px -40px 0px' }
);
revealElements.forEach((el) => revealObserver.observe(el));
// --- Nav scroll state ---
const nav = document.getElementById('nav');
const navLinks = document.querySelectorAll('.nav-links a');
const sections = document.querySelectorAll('section[id]');
function updateNav() {
if (window.scrollY > 60) {
nav.classList.add('scrolled');
} else {
nav.classList.remove('scrolled');
}
// Active section highlighting
let current = '';
sections.forEach((section) => {
const top = section.offsetTop - 120;
if (window.scrollY >= top) {
current = section.getAttribute('id');
}
});
navLinks.forEach((link) => {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + current) {
link.classList.add('active');
}
});
}
window.addEventListener('scroll', updateNav, { passive: true });
updateNav();
// --- Mobile menu ---
const navToggle = document.getElementById('navToggle');
const navMenu = document.getElementById('navLinks');
navToggle.addEventListener('click', () => {
navToggle.classList.toggle('active');
navMenu.classList.toggle('open');
document.body.style.overflow = navMenu.classList.contains('open') ? 'hidden' : '';
});
// Close mobile menu on link click
navMenu.querySelectorAll('a').forEach((link) => {
link.addEventListener('click', () => {
navToggle.classList.remove('active');
navMenu.classList.remove('open');
document.body.style.overflow = '';
});
});
// --- Smooth scroll for anchor links ---
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener('click', (e) => {
const target = document.querySelector(anchor.getAttribute('href'));
if (target) {
e.preventDefault();
const offset = 80; // nav height
const top = target.getBoundingClientRect().top + window.scrollY - offset;
window.scrollTo({ top, behavior: 'smooth' });
}
});
});
})();