Compare commits
2 Commits
1f324208d2
...
be006f08b4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be006f08b4 | ||
|
|
55ee3bddeb |
@@ -40,10 +40,24 @@ export const useOverlay = (listen = true) => {
|
|||||||
}, 80)
|
}, 80)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const scrollToElement = (element: HTMLElement) => {
|
||||||
|
const mainApp = document.getElementById("main-app")
|
||||||
|
if (!mainApp) return
|
||||||
|
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
const top =
|
||||||
|
element.getBoundingClientRect().top -
|
||||||
|
mainApp.getBoundingClientRect().top +
|
||||||
|
mainApp.scrollTop
|
||||||
|
mainApp.scrollTo({ top, behavior: "smooth" })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
isMobile,
|
isMobile,
|
||||||
scrollToNote
|
scrollToNote,
|
||||||
|
scrollToElement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export const useRouteQueryStackedNotes = () => {
|
|||||||
})
|
})
|
||||||
const { height } = useWindowSize()
|
const { height } = useWindowSize()
|
||||||
|
|
||||||
const { scrollToNote, isMobile } = useOverlay(false)
|
const { scrollToNote, scrollToElement, isMobile } = useOverlay(false)
|
||||||
|
|
||||||
const scrollToHashInNote = (
|
const scrollToHashInNote = (
|
||||||
cleanSha: string,
|
cleanSha: string,
|
||||||
@@ -57,7 +57,7 @@ export const useRouteQueryStackedNotes = () => {
|
|||||||
) as HTMLElement | null
|
) as HTMLElement | null
|
||||||
|
|
||||||
if (element) {
|
if (element) {
|
||||||
scrollToNote((index + 1) * element.clientHeight)
|
scrollToElement(element)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,8 +95,9 @@ export const router = createRouter({
|
|||||||
routes
|
routes
|
||||||
})
|
})
|
||||||
|
|
||||||
router.beforeEach(() => {
|
router.beforeEach((to, from) => {
|
||||||
if (!("startViewTransition" in document)) return
|
if (!("startViewTransition" in document)) return
|
||||||
|
if (to.path === from.path) return
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise<void>((resolve) => {
|
||||||
;(
|
;(
|
||||||
document as Document & {
|
document as Document & {
|
||||||
|
|||||||
Reference in New Issue
Block a user