From 6567c0f7b61df2f3c4b59b8753921c965f32844b Mon Sep 17 00:00:00 2001 From: cwchen <1048842385@qq.com> Date: Wed, 12 Nov 2025 15:52:11 +0800 Subject: [PATCH] =?UTF-8?q?word=20=E6=90=9C=E7=B4=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/common/DocumentSearchWord.vue | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/views/common/DocumentSearchWord.vue b/src/views/common/DocumentSearchWord.vue index c7dfbec..c2eced7 100644 --- a/src/views/common/DocumentSearchWord.vue +++ b/src/views/common/DocumentSearchWord.vue @@ -533,12 +533,22 @@ export default { return } + const wrapperRect = wrapper.getBoundingClientRect() + const margin = 24 + + const isInViewport = targetRect.top >= wrapperRect.top + margin && + targetRect.bottom <= wrapperRect.bottom - margin && + targetRect.left >= wrapperRect.left && + targetRect.right <= wrapperRect.right + + if (isInViewport) { + return + } + const performScroll = () => { try { - const wrapperRect = wrapper.getBoundingClientRect() const currentScrollTop = wrapper.scrollTop const targetTopRelativeToWrapper = targetRect.top - wrapperRect.top + currentScrollTop - const margin = 24 const desiredScrollTop = Math.max(targetTopRelativeToWrapper - margin, 0) if (useSmoothScroll) { @@ -555,7 +565,6 @@ export default { absoluteTop += node.offsetTop || 0 node = node.offsetParent } - const margin = 24 const desiredScrollTop = Math.max(absoluteTop - margin, 0) if (useSmoothScroll) {