-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
97 lines (86 loc) · 3.39 KB
/
script.js
File metadata and controls
97 lines (86 loc) · 3.39 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
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offset = 80; // Height of fixed header
const targetPosition = target.offsetTop - offset;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Add subtle parallax effect to hero section
const hero = document.querySelector('.hero');
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const rate = scrolled * -0.5;
if (hero) {
hero.style.transform = `translateY(${rate}px)`;
}
});
// Fade in elements on scroll
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Apply fade-in to sections
document.querySelectorAll('section:not(.hero)').forEach(section => {
section.style.opacity = '0';
section.style.transform = 'translateY(20px)';
section.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(section);
});
// Mobile menu functionality
const mobileMenuButton = document.querySelector('.mobile-menu-button');
const navLinks = document.querySelector('.nav-links');
if (mobileMenuButton) {
mobileMenuButton.addEventListener('click', () => {
const expanded = mobileMenuButton.getAttribute('aria-expanded') === 'true';
mobileMenuButton.setAttribute('aria-expanded', String(!expanded));
navLinks.classList.toggle('active');
mobileMenuButton.classList.toggle('active');
// Prevent body scroll when menu is open
document.body.style.overflow = navLinks.classList.contains('active') ? 'hidden' : '';
});
// Close menu when clicking on a link
document.querySelectorAll('.nav-links a').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('active');
mobileMenuButton.classList.remove('active');
mobileMenuButton.setAttribute('aria-expanded', 'false');
document.body.style.overflow = '';
});
});
// Close menu when clicking outside
document.addEventListener('click', (e) => {
if (!navLinks.contains(e.target) && !mobileMenuButton.contains(e.target)) {
navLinks.classList.remove('active');
mobileMenuButton.classList.remove('active');
mobileMenuButton.setAttribute('aria-expanded', 'false');
document.body.style.overflow = '';
}
});
}
// Navigation link highlighting
const sections = document.querySelectorAll('main section[id]');
const navItems = document.querySelectorAll('.nav-links a[href^="#"]');
const activateSection = () => {
let index = sections.length;
while (--index && window.scrollY + 90 < sections[index].offsetTop) {}
navItems.forEach(i => i.classList.remove('active'));
if (navItems[index]) navItems[index].classList.add('active');
};
window.addEventListener('scroll', activateSection);
activateSection();