8000 fix(onScrollLock): cache the el initial overflow value (#3527) · vueuse/vueuse@038666b · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 038666b

Browse files
authored
fix(onScrollLock): cache the el initial overflow value (#3527)
1 parent 931b279 commit 038666b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/core/useScrollLock/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ function preventDefault(rawEvent: TouchEvent): boolean {
4444
return false
4545
}
4646

47+
const elInitialOverflow = new WeakMap<HTMLElement, CSSStyleDeclaration['overflow']>()
48+
4749
/**
4850
* Lock scrolling of the element.
4951
*
@@ -62,7 +64,8 @@ export function useScrollLock(
6264
const target = resolveElement(toValue(el))
6365
if (target) {
6466
const ele = target as HTMLElement
65-
initialOverflow = ele.style.overflow
67+
if (!elInitialOverflow.get(ele))
68+
elInitialOverflow.set(ele, initialOverflow)
6669
if (isLocked.value)
6770
ele.style.overflow = 'hidden'
6871
}
@@ -91,7 +94,8 @@ export function useScrollLock(
9194
if (!el || !isLocked.value)
9295
return
9396
isIOS && stopTouchMoveListener?.()
94-
el.style.overflow = initialOverflow
97+
el.style.overflow = elInitialOverflow.get(el as HTMLElement) ?? ''
98+
elInitialOverflow.delete(el as HTMLElement)
9599
isLocked.value = false
96100
}
97101

0 commit comments

Comments
 (0)
0