18 lines
522 B
JavaScript
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'
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|