forked from Mirrors/elk
chore: prevent scroll on nav links
This commit is contained in:
parent
c546408326
commit
2a30510127
1 changed files with 9 additions and 2 deletions
|
@ -1,7 +1,14 @@
|
|||
export default defineNuxtPlugin(() => {
|
||||
export default defineNuxtPlugin((nuxt) => {
|
||||
return {
|
||||
provide: {
|
||||
scrollToTop: () => {
|
||||
scrollToTop: (evt?: MouseEvent | KeyboardEvent) => {
|
||||
const path = evt?.composedPath?.() as HTMLElement[]
|
||||
const el = path?.find(el => el.tagName?.toUpperCase() === 'A') as HTMLAnchorElement
|
||||
if (el && el.href) {
|
||||
if (nuxt.$preventScrollToTop(new URL(el.href, import.meta.url).pathname))
|
||||
return
|
||||
}
|
||||
|
||||
window.scrollTo({ top: 0, left: 0, behavior: 'smooth' })
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue