Files
remanso/src/hooks/useOverlay.hook.ts
Julien Calixte 63bc3f4d5d fix(mobile): scroll #main-app instead of body on mobile
body/html have overflow:hidden so scrollTop is a no-op on them.
#main-app is the actual scroll container; use overflow-y:auto on
mobile and target it directly in scrollToNote and the scroll listener.
2026-04-23 18:01:30 +02:00

50 lines
1.0 KiB
TypeScript

import { useEventListener, useWindowSize } from "@vueuse/core"
import { computed, ref } from "vue"
import { MOBILE_BREAKPOINT } from "@/constants/mobile"
export const useOverlay = (listen = true) => {
const x = ref(0)
const y = ref(0)
const { width } = useWindowSize()
const isMobile = computed(() => width.value <= MOBILE_BREAKPOINT)
if (listen) {
const updateScroll = () => {
const mainApp = document.getElementById("main-app")
x.value = mainApp?.scrollLeft ?? 0
y.value = mainApp?.scrollTop ?? 0
}
useEventListener(
() => document.getElementById("main-app"),
"scroll",
updateScroll,
{ passive: true }
)
}
const scrollToNote = (to: number) => {
const go = () => {
const mainApp = document.getElementById("main-app")
if (!mainApp) return
if (isMobile.value) {
mainApp.scrollTop = to
} else {
mainApp.scrollLeft = to
}
}
setTimeout(() => {
go()
}, 80)
}
return {
x,
y,
isMobile,
scrollToNote
}
}