link.addEventListener("click", event => { event.preventDefault(); const title = link.innerText; const url = link.getAttribute("href"); const page = url.split("#")[0]; const hash = url.split("#")[1]; const target = document.querySelector(`a[name="${hash}"], #${hash}`); if (window.location.pathname !== `/${page}`) { window.location = url; } if (target) { let options = { duration }; const to = getOffsetTop(target) - offset; scrollTo({ to, options }); if (window.history.pushState) { window.history.pushState(null, title, url); } else { window.location = url; } } });
onClickHandler(event) { event.preventDefault(); const options = { duration: this.options.duration }; const to = 0; scrollTo({ to, options }); }