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