mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-25 04:19:02 +08:00
improve scrolling again
This commit is contained in:
parent
a6041f2723
commit
e549f3954f
15
docs/gridsome.client.js
Normal file
15
docs/gridsome.client.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
export default function (Vue, options, context) {
|
||||||
|
|
||||||
|
context.router.afterEach(to => {
|
||||||
|
if (to.hash) {
|
||||||
|
setTimeout(() => {
|
||||||
|
const element = document.getElementById(to.hash.substr(1))
|
||||||
|
const top = element.offsetTop
|
||||||
|
const offset = parseFloat(getComputedStyle(element).scrollMarginTop)
|
||||||
|
|
||||||
|
window.scrollTo(0, top - offset)
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
@ -5,30 +5,9 @@ import 'prismjs/components/prism-scss.js'
|
|||||||
import PortalVue from 'portal-vue'
|
import PortalVue from 'portal-vue'
|
||||||
import App from '~/layouts/App'
|
import App from '~/layouts/App'
|
||||||
|
|
||||||
export default function (Vue, { router }) {
|
export default function (Vue) {
|
||||||
Vue.use(PortalVue)
|
Vue.use(PortalVue)
|
||||||
Vue.component('Layout', App)
|
Vue.component('Layout', App)
|
||||||
Vue.component('Demo', () => import(/* webpackChunkName: "demo" */ '~/components/Demo'))
|
Vue.component('Demo', () => import(/* webpackChunkName: "demo" */ '~/components/Demo'))
|
||||||
Vue.component('LiveDemo', () => import(/* webpackChunkName: "live-demo" */ '~/components/LiveDemo'))
|
Vue.component('LiveDemo', () => import(/* webpackChunkName: "live-demo" */ '~/components/LiveDemo'))
|
||||||
|
|
||||||
router.options.scrollBehavior = async (to, from, savedPosition) => {
|
|
||||||
if (to.hash) {
|
|
||||||
const elem = document.querySelector(to.hash)
|
|
||||||
|
|
||||||
if (elem) {
|
|
||||||
const offset = parseFloat(getComputedStyle(elem).scrollMarginTop)
|
|
||||||
return {
|
|
||||||
selector: to.hash,
|
|
||||||
offset: { y: offset },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (savedPosition) {
|
|
||||||
return savedPosition
|
|
||||||
}
|
|
||||||
|
|
||||||
return { x: 0, y: 0 }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user