UNPKG

quantumai-design-system

Version:

퀀텀에이아이의 디자인 시스템

30 lines (29 loc) 1.28 kB
import { useEffect } from 'react'; export function useScrollLock(lock, childCount) { if (childCount === void 0) { childCount = 0; } var scrollPosition = window.scrollY; var hasScrollY = document.body.scrollHeight > window.innerHeight; var hasScrollX = document.body.scrollWidth > window.innerWidth; useEffect(function () { if (document.body.classList.contains('lock') || !lock) return; if (!childCount) { document.body.style.position = 'fixed'; document.body.style.width = '100%'; document.body.style.overflowY = hasScrollY ? 'scroll' : 'hidden'; document.body.style.overflowX = hasScrollX ? 'scroll' : 'hidden'; document.body.style.top = "-".concat(scrollPosition, "px"); document.body.classList.add('lock'); } return function () { if (childCount >= 1) return; document.body.style.removeProperty('position'); document.body.style.removeProperty('width'); document.body.style.removeProperty('overflow'); document.body.style.removeProperty('top'); document.body.classList.remove('lock'); window.scrollTo(0, scrollPosition); }; }, []); }