brf/client/shared/utils/disable_scroll.ts
2025-12-13 21:12:08 +01:00

21 lines
571 B
TypeScript

const scrollingElement = typeof window !== 'undefined' && (document.scrollingElement || document.documentElement)
let scrollTop: number
export default {
disable() {
scrollTop = (document.scrollingElement || document.documentElement).scrollTop
document.body.style.top = `-${scrollTop}px`
document.body.style.position = 'fixed'
document.body.style.width = '100%'
},
enable() {
document.body.style.position = ''
document.body.style.top = ''
document.body.style.width = ''
;(scrollingElement as Element).scrollTop = scrollTop
},
}