From b4ad39db12b9b900080ce0d4c2db15e6ae05d7fd Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 18 Jul 2025 16:38:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=A8=E5=B1=80=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=E9=94=81=E5=AE=9A=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/composables/useScrollLock.ts | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/src/composables/useScrollLock.ts b/src/composables/useScrollLock.ts index c48a179d..46f9c627 100644 --- a/src/composables/useScrollLock.ts +++ b/src/composables/useScrollLock.ts @@ -86,9 +86,6 @@ const saveGlobalOriginalStyles = () => { globalOriginalStyles.value = { body: { overflow: document.body.style.overflow, - position: document.body.style.position, - top: document.body.style.top, - width: document.body.style.width, }, documentElement: { overflow: document.documentElement.style.overflow, @@ -113,21 +110,8 @@ const applyGlobalLockStyles = (config: any) => { if (globalLockCount.value === 1) { // 第一次锁定时应用样式 document.body.style.overflow = config.lockStyles.overflow || 'hidden' - document.body.style.position = config.lockStyles.position || 'fixed' - document.body.style.width = config.lockStyles.width || '100%' document.documentElement.style.overflow = config.lockStyles.overflow || 'hidden' document.documentElement.classList.add('v-overlay-scroll-blocked') - - // 如果需要保持滚动位置,设置top偏移 - if (config.preserveScrollPosition) { - document.body.style.top = `-${globalSavedScrollPosition.value}px` - } - - // 保持navbar的滚动状态 - 添加一个CSS变量来记录滚动位置 - if (globalSavedScrollPosition.value > 0) { - document.documentElement.style.setProperty('--saved-scroll-y', `${globalSavedScrollPosition.value}px`) - document.documentElement.classList.add('dialog-scroll-locked') - } } } @@ -136,22 +120,10 @@ const restoreGlobalStyles = (config: any) => { if (globalLockCount.value === 0 && globalOriginalStyles.value) { // 最后一个锁定时恢复样式 document.body.style.overflow = globalOriginalStyles.value.body.overflow || '' - document.body.style.position = globalOriginalStyles.value.body.position || '' - document.body.style.top = globalOriginalStyles.value.body.top || '' - document.body.style.width = globalOriginalStyles.value.body.width || '' document.documentElement.style.overflow = globalOriginalStyles.value.documentElement.overflow || '' // 移除 CSS 类名 document.documentElement.classList.remove('v-overlay-scroll-blocked') - document.documentElement.classList.remove('dialog-scroll-locked') - - // 移除CSS变量 - document.documentElement.style.removeProperty('--saved-scroll-y') - - // 恢复滚动位置 - if (config.preserveScrollPosition) { - window.scrollTo(0, globalSavedScrollPosition.value) - } // 重置全局状态 globalOriginalStyles.value = null