Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
FaizalZahid authored Aug 14, 2024
1 parent 9531018 commit 22ebd2d
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,29 @@ document.addEventListener("DOMContentLoaded", function() {
while(--index && window.scrollY + 50 < sections[index].offsetTop) {}

links.forEach((link) => link.classList.remove("active"));
links[index].classList.add("active");
if (links[index]) {
links[index].classList.add("active");
}
}

activateLink();
window.addEventListener("scroll", activateLink);

links.forEach((link) => {
link.addEventListener("click", function(e) {
e.preventDefault();
const targetId = this.getAttribute("href").substring(1);
const targetSection = document.getElementById(targetId);
const href = link.getAttribute("href");
if (href && href.startswith('#')) {
link.addEventListener("click", function(e) {
e.preventDefault();
const targetId = this.getAttribute("href").substring(1);
const targetSection = document.getElementById(targetId);

window.scrollTo({
top: targetSection.offsetTop,
behavior: "smooth",
if (targetSection) {
window.scrollTo({
top: targetSection.offsetTop,
behavior: "smooth",
});
}
});
});
}
});
});
});

0 comments on commit 22ebd2d

Please sign in to comment.