-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (39 loc) · 1.71 KB
/
script.js
File metadata and controls
45 lines (39 loc) · 1.71 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
document.addEventListener('DOMContentLoaded', () => {
const navToggle = document.querySelector('.nav-toggle');
const navList = document.querySelector('.nav-list');
const navLinks = document.querySelectorAll('.nav-link'); // Get all nav links
// Toggle navigation menu on mobile
if (navToggle && navList) {
navToggle.addEventListener('click', () => {
navList.classList.toggle('active');
navToggle.classList.toggle('active'); // Add active class to toggle button for animation
});
}
// Close navigation menu when a link is clicked (for smooth scrolling)
navLinks.forEach(link => {
link.addEventListener('click', () => {
if (navList.classList.contains('active')) {
navList.classList.remove('active');
navToggle.classList.remove('active');
}
});
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Basic form submission example (prevent default for demonstration)
const contactForm = document.querySelector('.contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault(); // Prevent actual form submission
alert('Message Sent! (This is a demo. In a real scenario, data would be sent to a server.)');
this.reset(); // Clear form fields
});
}
});