From fd2b500ebbcf97dc5c67cf41c9785ec386e3b45b Mon Sep 17 00:00:00 2001 From: giteaadmin Date: Wed, 6 Aug 2025 23:01:44 -0400 Subject: [PATCH] smooth scroll homepage link --- src/js/main.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/js/main.js b/src/js/main.js index 6b5f9d8..25db1dd 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -16,8 +16,9 @@ let isDeleting = false; function type() { const currentText = text.substring(0, index); - typewriterElement.textContent = currentText; - + if (typewriterElement) { + typewriterElement.textContent = currentText; + } if (!isDeleting && index < text.length) { index++; setTimeout(type, 100); @@ -28,7 +29,9 @@ function type() { // Start typing effect on load document.addEventListener('DOMContentLoaded', () => { - setTimeout(type, 500); + if (typewriterElement) { + setTimeout(type, 500); + } }); // Smooth scrolling for anchor links @@ -55,4 +58,19 @@ document.querySelectorAll('a[href^="/#"]').forEach(anchor => { mobileMenu.classList.add('hidden'); } }); -}); \ No newline at end of file +}); + +// Smooth scrolling for the main home link +document.querySelectorAll('a[href="/"]').forEach(anchor => { + anchor.addEventListener('click', function(e) { + // If we are already on the homepage + if (window.location.pathname === '/') { + e.preventDefault(); // Prevent the page from reloading + // Scroll smoothly to the top of the page + window.scrollTo({ + top: 0, + behavior: 'smooth' + }); + } + }); +});