gctGenerator/site/.vuepress/enhanceApp.js

19 lines
548 B
JavaScript
Raw Normal View History

2022-01-17 03:17:07 +09:00
export default ({ isServer }) => {
2021-06-11 07:48:15 +09:00
if (isServer) return;
2020-09-26 23:07:24 +09:00
document.onreadystatechange = () => {
if (document.readyState === 'complete') {
2021-04-01 06:06:05 +09:00
if (location.hash && location.hash.length > 0) {
const { hash } = location;
2020-09-26 23:07:24 +09:00
2021-04-01 06:06:05 +09: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 23:07:24 +09:00
}
}
};
2020-06-29 00:35:18 +09:00
};