(fix) ハッシュに移動した際のスクロール位置がおかしい

fix #89
This commit is contained in:
kakkokari-gtyih 2023-12-27 22:22:47 +09:00
parent 077f18b90b
commit e2438ba03e
3 changed files with 35 additions and 5 deletions

View File

@ -20,11 +20,6 @@ router.beforeEach((to, from) => {
}
})
nuxtApp.hook('page:loading:start', () => {
if (!NProgress.isStarted()) {
NProgress.start();
}
});
nuxtApp.hook('page:loading:end', () => {
nextTick(() => {
setTimeout(() => {

34
app/router.options.ts Normal file
View File

@ -0,0 +1,34 @@
import type { RouterConfig } from '@nuxt/schema'
export default <RouterConfig> {
scrollBehavior(to, from, savedPosition) {
const width = window ? window.innerWidth : 0;
if (savedPosition) {
return savedPosition;
} else if (to.meta.layout && to.hash) {
switch (to.meta.layout) {
case 'blank':
return { el: to.hash };
case 'docs':
if (width < 1024) {
return { top: 128, el: to.hash };
} else {
return { top: 80, el: to.hash };
}
case 'slim':
case 'tools':
return { top: 80, el: to.hash };
default:
if (width < 1024) {
return { top: 80, el: to.hash };
} else {
return { top: 96, el: to.hash };
}
}
}
},
}

View File

@ -14,6 +14,7 @@ export default <Config> {
],
safelist: [
'scroll-pt-20',
'scroll-pt-24',
'scroll-pt-32',
'lg:scroll-pt-4',
'lg:scroll-pt-20',