tiptap/docs/gridsome.client.js

27 lines
549 B
JavaScript
Raw Normal View History

2020-10-16 15:28:14 +08:00
export default function (Vue, options, context) {
2020-10-31 01:11:54 +08:00
Vue.mixin({
data() {
return {
cwd: options.cwd,
}
},
})
2020-10-16 15:28:14 +08:00
context.router.afterEach(to => {
if (to.hash) {
setTimeout(() => {
const element = document.getElementById(to.hash.substr(1))
const top = element.offsetTop
2020-11-20 07:11:13 +08:00
const offset = parseFloat(
getComputedStyle(element).scrollMarginTop
|| getComputedStyle(element).scrollSnapMarginTop,
)
2020-10-16 15:28:14 +08:00
window.scrollTo(0, top - offset)
}, 0)
}
})
}