-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
103 lines (92 loc) · 3.61 KB
/
Copy pathscript.js
File metadata and controls
103 lines (92 loc) · 3.61 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
97
98
99
100
101
102
103
document.addEventListener('DOMContentLoaded', () => {
// Mobile Menu Toggle
const mobileMenu = document.getElementById('mobile-menu');
const navLinks = document.querySelector('.nav-links');
if (mobileMenu && navLinks) {
mobileMenu.addEventListener('click', () => {
navLinks.classList.toggle('active');
const icon = mobileMenu.querySelector('i');
if (icon.classList.contains('fa-bars')) {
icon.classList.remove('fa-bars');
icon.classList.add('fa-xmark');
} else {
icon.classList.remove('fa-xmark');
icon.classList.add('fa-bars');
}
});
// Close menu on click of links
const links = navLinks.querySelectorAll('a');
links.forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('active');
const icon = mobileMenu.querySelector('i');
icon.classList.remove('fa-xmark');
icon.classList.add('fa-bars');
});
});
}
// Navbar Scroll Background Change
const navbar = document.getElementById('navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.style.padding = '12px 0';
navbar.style.background = 'rgba(11, 15, 25, 0.95)';
navbar.style.boxShadow = '0 10px 30px rgba(0,0,0,0.4)';
} else {
navbar.style.padding = '18px 0';
navbar.style.background = 'rgba(11, 15, 25, 0.85)';
navbar.style.boxShadow = 'none';
}
});
// Active Link Highlighting on Scroll
const sections = document.querySelectorAll('section');
const navItems = document.querySelectorAll('.nav-links a:not(.btn-nav)');
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (window.scrollY >= (sectionTop - 150)) {
current = section.getAttribute('id');
}
});
navItems.forEach(item => {
item.classList.remove('active-link');
if (item.getAttribute('href').slice(1) === current) {
item.classList.add('active-link');
}
});
});
// Dynamic Scroll Reveal Animation using Intersection Observer
const revealElements = document.querySelectorAll('section, .project-card, .skills-category, .timeline-item, .about-card');
revealElements.forEach(el => {
el.classList.add('reveal');
});
const revealObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('active');
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -60px 0px'
});
revealElements.forEach(el => {
revealObserver.observe(el);
});
// Render Mermaid diagrams on demand when accordions are opened
document.querySelectorAll('.project-details-diagram').forEach((accordion) => {
accordion.addEventListener('toggle', () => {
if (accordion.open) {
const mermaidDiv = accordion.querySelector('.mermaid');
if (mermaidDiv && !mermaidDiv.hasAttribute('data-processed')) {
mermaid.run({
nodes: [mermaidDiv]
});
}
}
});
});
});