diff --git a/src/components/sp-page/index.js b/src/components/sp-page/index.js index 9a538e8b8..57572143a 100644 --- a/src/components/sp-page/index.js +++ b/src/components/sp-page/index.js @@ -85,18 +85,28 @@ const SpPage = memo( useEffect(() => { if (state.lock) { + // 保存当前滚动位置 + const currentScrollTop = scrollTopRef.current || 0 + setState((draft) => { draft.lockStyle = { - position: 'fixed', - top: `-${scrollTopRef.current}px`, - left: '0px', - width: '100%', - bottom: '0px' + overflow: 'hidden' } }) + + // 设置滚动位置,防止回到顶部 + setTimeout(() => { + Taro.pageScrollTo({ + scrollTop: currentScrollTop, + duration: 0 + }) + }, 0) + } else { setState((draft) => { - draft.lockStyle = {} + draft.lockStyle = { + overflow: 'auto' + } }) } }, [state.lock]) @@ -260,13 +270,6 @@ const SpPage = memo( setState((draft) => { draft.lock = false }) - - setTimeout(() => { - Taro.pageScrollTo({ - scrollTop: scrollTopRef.current, - duration: 0 - }) - }, 0) } })) const computedNavigationStyle = () => {