notebook/app/assets/javascripts/smoothscrolling.js
2023-04-07 17:47:08 -07:00

15 lines
378 B
JavaScript

document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
// Check if the target element exists
if (target) {
window.scrollTo({
top: target.offsetTop,
behavior: 'smooth',
});
}
});
});