Public Access
1
0

implemented blog posts

This commit is contained in:
2025-08-05 23:10:57 -04:00
parent 56bde4626c
commit c1fa3e8863
6 changed files with 72 additions and 8 deletions

View File

@@ -8,22 +8,26 @@ if (mobileMenuButton && mobileMenu) {
});
}
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="/#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
let targetId = this.getAttribute('href').substring(2);
let targetElement = document.getElementById(targetId);
if (targetElement) {
// Check if the current page is the homepage.
const isHomePage = window.location.pathname === '/';
const targetId = this.getAttribute('href').substring(2);
const targetElement = document.getElementById(targetId);
// If we are on the homepage AND the target element exists, then smooth scroll.
if (isHomePage && targetElement) {
e.preventDefault(); // Stop the browser from navigating.
targetElement.scrollIntoView({
behavior: 'smooth'
});
}
// If we are on any other page (like /blog/), this 'if' condition is false,
// so e.preventDefault() is NOT called, and the browser performs its
// default action: navigating to the homepage and jumping to the hash.
// Close mobile menu on link click
// Close mobile menu on any nav link click
if (mobileMenu && !mobileMenu.classList.contains('hidden')) {
mobileMenu.classList.add('hidden');
}