Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
96 lines (86 loc) · 3.33 KB
/
Copy pathscript.js
File metadata and controls
96 lines (86 loc) · 3.33 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
90
91
92
93
94
95
96
// Mobile Navigation Toggle
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
if (hamburger && navMenu) {
hamburger.addEventListener('click', () => {
navMenu.classList.toggle('active');
hamburger.classList.toggle('active');
});
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', () => {
navMenu.classList.remove('active');
hamburger.classList.remove('active');
});
});
}
// Mark active nav link based on current page
(function markActiveNav() {
const page = location.pathname.split('/').pop() || 'index.html';
document.querySelectorAll('.nav-link').forEach(link => {
const href = link.getAttribute('href') || '';
const hrefPage = href.split('/').pop().split('#')[0];
if (hrefPage && hrefPage === page) {
link.classList.add('active');
} else if (page === '' && hrefPage === 'index.html') {
link.classList.add('active');
}
});
})();
// Update last updated date
const lastUpdatedEl = document.getElementById('last-updated');
if (lastUpdatedEl) {
lastUpdatedEl.textContent = new Date().toLocaleDateString('en-US', {
year: 'numeric', month: 'long', day: 'numeric'
});
}
// Smooth scroll for anchor links on the same page
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const target = document.querySelector(this.getAttribute('href'));
if (target) {
e.preventDefault();
window.scrollTo({ top: target.offsetTop - 75, behavior: 'smooth' });
}
});
});
// Navbar shadow on scroll
window.addEventListener('scroll', () => {
const navbar = document.querySelector('.navbar');
if (!navbar) return;
navbar.style.backgroundColor = window.scrollY > 50
? 'rgba(255,255,255,0.98)'
: 'rgba(255,255,255,0.95)';
});
// Fade-in animation
const fadeEls = document.querySelectorAll('.section, .section-alt');
if ('IntersectionObserver' in window && fadeEls.length) {
const obs = new IntersectionObserver(entries => {
entries.forEach(e => {
if (e.isIntersecting) {
e.target.style.opacity = '1';
e.target.style.transform = 'translateY(0)';
}
});
}, { threshold: 0, rootMargin: '0px 0px -40px 0px' });
fadeEls.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(18px)';
el.style.transition = 'opacity 0.55s ease, transform 0.55s ease';
obs.observe(el);
});
} else {
fadeEls.forEach(el => { el.style.opacity = '1'; el.style.transform = 'none'; });
}
// Generic filter buttons (projects / news pages)
document.querySelectorAll('.filter-btn').forEach(btn => {
btn.addEventListener('click', () => {
const group = btn.closest('.project-filter, .news-filter');
if (group) group.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
const target = btn.dataset.filter;
const cards = document.querySelectorAll('[data-category]');
cards.forEach(card => {
card.style.display = (target === 'all' || card.dataset.category === target) ? '' : 'none';
});
});
});