scroll top on navigate
This commit is contained in:
parent
e625f97027
commit
aceb33fe6a
25
plugins/scroll-top.ts
Normal file
25
plugins/scroll-top.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { defineNuxtPlugin } from '#imports';
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
nuxtApp.$router.options.scrollBehavior = async (to, from, savedPosition) => {
|
||||
let goTo;
|
||||
|
||||
if (to.hash) {
|
||||
goTo = {
|
||||
el: to.hash,
|
||||
behavior: 'smooth',
|
||||
top: 64,
|
||||
};
|
||||
} else if (savedPosition) {
|
||||
goTo = savedPosition;
|
||||
} else {
|
||||
goTo = { top: 0 };
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve(goTo);
|
||||
}, 100);
|
||||
});
|
||||
};
|
||||
});
|
Loading…
Reference in New Issue
Block a user