Skip to content

Commit

Permalink
Update script.js smooth
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardik-S authored Nov 14, 2024
1 parent 7a5d4c8 commit 3197b54
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,19 @@ function createBubble(x, y) {
bubble.remove();
});
}

document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();

const targetId = this.getAttribute('href').substring(1);
const targetElement = document.getElementById(targetId);

if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop,
behavior: 'smooth'
});
}
});
});

0 comments on commit 3197b54

Please sign in to comment.