scroll-lock-body
Version:
scroll lock the body and remember the position
1 lines • 1.41 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["const attribute = 'data-scroll-lock-is-active';\nconst html = document.documentElement;\n\nexport const enableScrollLock = (): void => {\n if (window.scrollY) {\n document.body.style.marginTop = `-${window.scrollY}px`;\n }\n html.setAttribute(attribute, '');\n};\n\nexport const disableScrollLock = (): void => {\n const scrollY = document.body.style.marginTop;\n document.body.style.marginTop = '';\n html.removeAttribute(attribute);\n\n if (scrollY) {\n window.scrollTo(0, parseInt(scrollY || '0') * -1);\n }\n};\n\nexport const isScrollLockEnabled = (): boolean => {\n return html.getAttribute(attribute) != null;\n};\n"],"names":[],"mappings":";;;;;;;;;;AAAA,IAAM,SAAS,GAAG,4BAA4B,CAAC;AAC/C,IAAM,IAAI,GAAG,QAAQ,CAAC,eAAe,CAAC;IAEzB,gBAAgB,GAAG;IAC9B,IAAI,MAAM,CAAC,OAAO,EAAE;QAClB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,MAAI,MAAM,CAAC,OAAO,OAAI,CAAC;KACxD;IACD,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;AACnC,EAAE;IAEW,iBAAiB,GAAG;IAC/B,IAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;IAC9C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE,CAAC;IACnC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IAEhC,IAAI,OAAO,EAAE;QACX,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KACnD;AACH,EAAE;IAEW,mBAAmB,GAAG;IACjC,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC;AAC9C;;;;;;"}