gctGenerator/site/.vuepress/enhanceApp.js
Matteias Collet 79fab84fae minor cleanup
2022-01-16 18:17:07 +00:00

18 lines
548 B
JavaScript
Executable file

export default ({ isServer }) => {
if (isServer) return;
document.onreadystatechange = () => {
if (document.readyState === 'complete') {
if (location.hash && location.hash.length > 0) {
const { hash } = location;
const decoded = decodeURIComponent(hash);
const targetAnchor = document.querySelector(decoded) ?? document.querySelector(hash);
if (targetAnchor && targetAnchor.offsetTop) {
window.scrollTo({ top: targetAnchor.offsetTop, behavior: 'smooth' });
}
}
}
};
};