mirror of
https://github.com/elk-zone/elk.git
synced 2024-12-05 03:59:59 +03:00
16 lines
507 B
TypeScript
16 lines
507 B
TypeScript
export default defineNuxtPlugin((nuxt) => {
|
|
return {
|
|
provide: {
|
|
scrollToTop: (evt?: MouseEvent | KeyboardEvent) => {
|
|
const path = evt?.composedPath?.() as HTMLElement[]
|
|
const el = path?.find(el => el.tagName?.toUpperCase() === 'A') as HTMLAnchorElement
|
|
if (el?.href) {
|
|
if (nuxt.$preventScrollToTop(new URL(el.href, import.meta.url).pathname))
|
|
return
|
|
}
|
|
|
|
window.scrollTo({ top: 0, left: 0, behavior: 'smooth' })
|
|
},
|
|
},
|
|
}
|
|
})
|