diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2206544 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.codegpt \ No newline at end of file diff --git a/assets/js/script.js b/assets/js/script.js index 93dd2d8..70d4f57 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -45,6 +45,34 @@ const toggleNavbar = function () { addEventOnElements(navTogglers, "click", toggleNavbar); +// Fixes Nav link + +document.addEventListener("DOMContentLoaded", function () { + const navLinks = document.querySelectorAll(".navbar-link"); + const currentPage = window.location.pathname.split("/").pop(); + let currentHash = window.location.hash; + + if (currentPage === "index.html" && currentHash === "") { + currentHash = "#home"; + } + + navLinks.forEach((link) => { + const linkPath = link.getAttribute("href"); + const linkHrefPath = linkPath.split("#")[0].split("/").pop(); + const linkHash = linkPath.split("#")[1] || ""; + + if (currentPage === linkHrefPath) { + if (currentHash === `#${linkHash}` || (currentHash === "" && linkHash === "")) { + link.classList.add("active"); + } else { + link.classList.remove("active"); + } + } else { + link.classList.remove("active"); + } + }); +}); + /** @@ -170,38 +198,38 @@ window.addEventListener("mousemove", function (event) { }); - const fadeInElements = document.querySelectorAll('.fade-in'); - const slideInElements = document.querySelectorAll('.slide-in'); - const scaleUpElements = document.querySelectorAll('.scale-up'); - - const handleScroll = () => { - fadeInElements.forEach((el) => { - const rect = el.getBoundingClientRect(); - if (rect.top < window.innerHeight && rect.bottom > 0) { - el.classList.add('visible'); - } else { - el.classList.remove('visible'); - } - }); - - slideInElements.forEach((el) => { - const rect = el.getBoundingClientRect(); - if (rect.top < window.innerHeight && rect.bottom > 0) { - el.classList.add('visible'); - } else { - el.classList.remove('visible'); - } - }); - - scaleUpElements.forEach((el) => { - const rect = el.getBoundingClientRect(); - if (rect.top < window.innerHeight && rect.bottom > 0) { - el.classList.add('visible'); - } else { - el.classList.remove('visible'); - } - }); - }; - - window.addEventListener('scroll', handleScroll); - handleScroll(); \ No newline at end of file +const fadeInElements = document.querySelectorAll('.fade-in'); +const slideInElements = document.querySelectorAll('.slide-in'); +const scaleUpElements = document.querySelectorAll('.scale-up'); + +const handleScroll = () => { + fadeInElements.forEach((el) => { + const rect = el.getBoundingClientRect(); + if (rect.top < window.innerHeight && rect.bottom > 0) { + el.classList.add('visible'); + } else { + el.classList.remove('visible'); + } + }); + + slideInElements.forEach((el) => { + const rect = el.getBoundingClientRect(); + if (rect.top < window.innerHeight && rect.bottom > 0) { + el.classList.add('visible'); + } else { + el.classList.remove('visible'); + } + }); + + scaleUpElements.forEach((el) => { + const rect = el.getBoundingClientRect(); + if (rect.top < window.innerHeight && rect.bottom > 0) { + el.classList.add('visible'); + } else { + el.classList.remove('visible'); + } + }); +}; + +window.addEventListener('scroll', handleScroll); +handleScroll(); \ No newline at end of file