Skip to content

Commit

Permalink
Merge pull request #3 from sammy0318/merge
Browse files Browse the repository at this point in the history
updated js
  • Loading branch information
sammy0318 authored Dec 22, 2024
2 parents 8f20ab2 + 0ebbcc2 commit 8118fbc
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions Garima.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
// Smooth scroll effect for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();

document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});

// Responsive menu toggle
// 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 Scrolling
// Smooth scroll for all anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();

document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
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');
}
}
});
});



scrollToTopBtn.addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});

// Close mobile menu when a nav link is clicked
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('open');
// Scroll to top functionality
if (scrollToTopBtn) {
scrollToTopBtn.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
});
}

0 comments on commit 8118fbc

Please sign in to comment.