-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
138 lines (118 loc) · 4.08 KB
/
Copy pathscript.js
File metadata and controls
138 lines (118 loc) · 4.08 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
document.addEventListener('DOMContentLoaded', () => {
// DOM Elements
const navbar = document.getElementById('navbar');
const mobileMenuButton = document.getElementById('mobile-menu-button');
const mobileMenu = document.getElementById('mobile-menu');
const navLinks = document.querySelectorAll('.nav-link');
const mobileNavLinks = document.querySelectorAll('.mobile-nav-link');
const sections = document.querySelectorAll('section');
const bgElements = document.querySelectorAll('.fixed > div');
// Mobile Menu Toggle
mobileMenuButton.addEventListener('click', () => {
mobileMenuButton.classList.toggle('active');
if (mobileMenu.classList.contains('open')) {
mobileMenu.style.height = '0';
mobileMenu.classList.remove('open');
} else {
mobileMenu.classList.add('open');
mobileMenu.style.height = `${mobileMenu.scrollHeight}px`;
}
});
// Close mobile menu when a link is clicked
mobileNavLinks.forEach(link => {
link.addEventListener('click', () => {
mobileMenuButton.classList.remove('active');
mobileMenu.style.height = '0';
mobileMenu.classList.remove('open');
});
});
// Navbar scroll effect
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
highlightCurrentSection();
});
// Smooth scroll for nav links
navLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const targetId = link.getAttribute('href');
const targetSection = document.querySelector(targetId);
if (targetSection) {
const offsetTop = targetSection.offsetTop - 70; // Adjust for navbar height
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
// Highlight the section briefly
targetSection.classList.add('section-highlight');
setTimeout(() => {
targetSection.classList.remove('section-highlight');
}, 1000);
}
});
});
// Highlight active section in navbar
function highlightCurrentSection() {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop - 100;
const sectionHeight = section.offsetHeight;
if (window.scrollY >= sectionTop && window.scrollY < sectionTop + sectionHeight) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
mobileNavLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
}
// Parallax effect for background elements
/*
if (window.matchMedia('(prefers-reduced-motion: no-preference)').matches) {
document.addEventListener('mousemove', (e) => {
const x = e.clientX / window.innerWidth;
const y = e.clientY / window.innerHeight;
bgElements.forEach(element => {
const speed = 20; // Adjust for more or less movement
const xOffset = (x - 0.5) * speed;
const yOffset = (y - 0.5) * speed;
element.style.transform = `translate(${xOffset}px, ${yOffset}px)`;
});
});
}
*/
// Scroll animations for sections
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('section-visible');
}
});
}, { threshold: 0.1 });
sections.forEach(section => {
section.classList.add('section-hidden');
observer.observe(section);
});
// Initialize active section on page load
highlightCurrentSection();
// Make header text visible with animation
setTimeout(() => {
const headerText = document.querySelector('.text-6xl');
if (headerText) {
headerText.style.opacity = 1;
headerText.style.transform = 'translateY(0)';
}
}, 300);
});