-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGarima.js
44 lines (39 loc) · 1.41 KB
/
Garima.js
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
// Select DOM elements
const menuToggle = document.querySelector('.menu-toggle');
const navLinks = document.querySelector('.nav-links');
const scrollToTopBtn = document.querySelector('.scroll-to-top'); // Make sure you have this element in your HTML
// Toggle mobile menu
menuToggle.addEventListener('click', () => {
navLinks.classList.toggle('open');
// Optional: Toggle aria-expanded attribute for accessibility
menuToggle.setAttribute(
'aria-expanded',
menuToggle.getAttribute('aria-expanded') === 'false' ? 'true' : 'false'
);
});
// Smooth scroll for all anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetElement = document.querySelector(this.getAttribute('href'));
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth'
});
// Close mobile menu when a link is clicked
if (navLinks.classList.contains('open')) {
navLinks.classList.remove('open');
menuToggle.setAttribute('aria-expanded', 'false');
}
}
});
});
// Scroll to top functionality
if (scrollToTopBtn) {
scrollToTopBtn.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
}