-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
107 lines (85 loc) · 3.39 KB
/
script.js
File metadata and controls
107 lines (85 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
98
99
100
101
102
103
104
105
106
107
document.addEventListener('DOMContentLoaded', function() {
// Mobile menu toggle
const menuButton = document.getElementById('menuButton');
const mobileMenu = document.getElementById('mobileMenu');
if (menuButton && mobileMenu) {
menuButton.addEventListener('click', function() {
mobileMenu.classList.toggle('show');
});
}
// Smooth scrolling for navigation links
const navLinks = document.querySelectorAll('a[href^="#"]');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
const targetId = this.getAttribute('href');
if (targetId === '#') return;
e.preventDefault();
const targetElement = document.querySelector(targetId);
if (targetElement) {
// Close mobile menu if open
if (mobileMenu && mobileMenu.classList.contains('show')) {
mobileMenu.classList.remove('show');
}
// Scroll to target
window.scrollTo({
top: targetElement.offsetTop - 80, // Adjust for header height
behavior: 'smooth'
});
}
});
});
// // Form submission handling
// const contactForm = document.querySelector('.contact-form');
// if (contactForm) {
// contactForm.addEventListener('submit', function(e) {
// e.preventDefault();
// // Get form data
// const formData = {
// name: document.getElementById('name').value,
// email: document.getElementById('email').value,
// subject: document.getElementById('subject').value,
// message: document.getElementById('message').value
// };
// // Here you would typically send the data to a server
// console.log('Form submitted:', formData);
// // Show success message (in a real implementation, this would happen after successful submission)
// const successMessage = document.createElement('div');
// successMessage.className = 'success-message';
// successMessage.textContent = 'Message sent successfully!';
// contactForm.appendChild(successMessage);
// // Reset form
// contactForm.reset();
// // Remove success message after 3 seconds
// setTimeout(() => {
// successMessage.remove();
// }, 3000);
// });
// }
// Active navigation highlighting based on scroll position
function highlightActiveNavLink() {
const sections = document.querySelectorAll('section[id]');
const scrollPosition = window.scrollY;
sections.forEach(section => {
const sectionTop = section.offsetTop - 100;
const sectionHeight = section.offsetHeight;
const sectionId = section.getAttribute('id');
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
// Remove active class from all links
navLinks.forEach(link => {
link.classList.remove('active');
});
// Add active class to current section link
const activeLink = document.querySelector(`a[href="#${sectionId}"]`);
if (activeLink) {
activeLink.classList.add('active');
}
}
});
}
window.addEventListener('scroll', highlightActiveNavLink);
// Update copyright year
const copyrightYear = document.querySelector('.copyright-year');
if (copyrightYear) {
copyrightYear.textContent = new Date().getFullYear();
}
});