Last active
September 16, 2023 08:58
-
-
Save moaoa/9182ec933c9d67f06bc8b27fe7ab7b32 to your computer and use it in GitHub Desktop.
vue_3_scrolllBehavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const Router = createRouter({ | |
history: createWebHistory(), | |
routes, | |
scrollBehavior: (to, from, savedPosition) => { | |
if (to && to.hash) { | |
return { el: to.hash, behavior: 'smooth' }; | |
} else { | |
return { x: 0, y: 0 }; | |
} | |
}, | |
}); | |
//another example | |
const router = createRouter({ | |
scrollBehavior(to, from, savedPosition) { | |
// always scroll 10px above the element #main | |
return { | |
// could also be | |
// el: document.getElementById('main'), | |
el: '#main', | |
top: -10, | |
} | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment