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) {