gctGenerator/site/.vuepress/enhanceApp.js

19 lines
548 B
JavaScript
Raw Normal View History

2022-01-16 18:17:07 +00:00
export default ({ isServer }) => {
2021-06-11 00:48:15 +02:00
if (isServer) return;
2020-09-26 16:07:24 +02:00
document.onreadystatechange = () => {
if (document.readyState === 'complete') {
2021-03-31 23:06:05 +02:00
if (location.hash && location.hash.length > 0) {
const { hash } = location;
2020-09-26 16:07:24 +02:00
2021-03-31 23:06:05 +02:00
const decoded = decodeURIComponent(hash);
const targetAnchor = document.querySelector(decoded) ?? document.querySelector(hash);
if (targetAnchor && targetAnchor.offsetTop) {
window.scrollTo({ top: targetAnchor.offsetTop, behavior: 'smooth' });
}
2020-09-26 16:07:24 +02:00
}
}
};
2020-06-28 17:35:18 +02:00
};