improve scroll position

This commit is contained in:
Philipp Kühn 2020-10-16 09:11:09 +02:00
parent 7e33b748d1
commit a6041f2723
2 changed files with 26 additions and 1 deletions

View File

@ -59,6 +59,10 @@ body {
color: $colorText;
}
*[id] {
scroll-margin-top: 6rem;
}
button {
font: inherit;
cursor: pointer;

View File

@ -5,9 +5,30 @@ import 'prismjs/components/prism-scss.js'
import PortalVue from 'portal-vue'
import App from '~/layouts/App'
export default function (Vue) {
export default function (Vue, { router }) {
Vue.use(PortalVue)
Vue.component('Layout', App)
Vue.component('Demo', () => import(/* webpackChunkName: "demo" */ '~/components/Demo'))
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 }
}
}