budgit/assets/js/smooth-scroll.js
2026-02-07 18:27:27 +00:00

18 lines
522 B
JavaScript

document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
// Only prevent default for same-page anchors
const href = this.getAttribute('href');
if (href && href !== '#' && href.startsWith('#')) {
const target = document.querySelector(href);
if (target) {
e.preventDefault();
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
});
});
});