Download packages/@core/composables/src/use-scroll-lock.ts from binhugg3/admin: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/binhugg3/admin/resolve/main/packages/%40core/composables/src/use-scroll-lock.ts
- Command line
-
hf download hf://spaces/binhugg3/admin/packages/@core/composables/src/use-scroll-lock.ts
-
curl -L -o use-scroll-lock.ts https://huggingface.co/spaces/binhugg3/admin/resolve/main/packages/%40core/composables/src/use-scroll-lock.ts
1.45 kB
| import { getScrollbarWidth, needsScrollbar } from '@vben-core/shared/utils'; | |
| import { | |
| useScrollLock as _useScrollLock, | |
| tryOnBeforeUnmount, | |
| tryOnMounted, | |
| } from '@vueuse/core'; | |
| export const SCROLL_FIXED_CLASS = `_scroll__fixed_`; | |
| export function useScrollLock() { | |
| const isLocked = _useScrollLock(document.body); | |
| const scrollbarWidth = getScrollbarWidth(); | |
| tryOnMounted(() => { | |
| if (!needsScrollbar()) { | |
| return; | |
| } | |
| document.body.style.paddingRight = `${scrollbarWidth}px`; | |
| const layoutFixedNodes = document.querySelectorAll<HTMLElement>( | |
| `.${SCROLL_FIXED_CLASS}`, | |
| ); | |
| const nodes = [...layoutFixedNodes]; | |
| if (nodes.length > 0) { | |
| nodes.forEach((node) => { | |
| node.dataset.transition = node.style.transition; | |
| node.style.transition = 'none'; | |
| node.style.paddingRight = `${scrollbarWidth}px`; | |
| }); | |
| } | |
| isLocked.value = true; | |
| }); | |
| tryOnBeforeUnmount(() => { | |
| if (!needsScrollbar()) { | |
| return; | |
| } | |
| isLocked.value = false; | |
| const layoutFixedNodes = document.querySelectorAll<HTMLElement>( | |
| `.${SCROLL_FIXED_CLASS}`, | |
| ); | |
| const nodes = [...layoutFixedNodes]; | |
| if (nodes.length > 0) { | |
| nodes.forEach((node) => { | |
| node.style.paddingRight = ''; | |
| requestAnimationFrame(() => { | |
| node.style.transition = node.dataset.transition || ''; | |
| }); | |
| }); | |
| } | |
| document.body.style.paddingRight = ''; | |
| }); | |
| } | |