From ed03901ba8589224d3f59a056f7a045297ea4a0e Mon Sep 17 00:00:00 2001 From: cwchen <1048842385@qq.com> Date: Thu, 27 Nov 2025 18:44:18 +0800 Subject: [PATCH] =?UTF-8?q?pdf=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/DocumentSearch.vue | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/views/common/DocumentSearch.vue b/src/views/common/DocumentSearch.vue index 40f33a9..e5402b1 100644 --- a/src/views/common/DocumentSearch.vue +++ b/src/views/common/DocumentSearch.vue @@ -823,17 +823,34 @@ export default { if (!target) return const wrapper = this.$refs.pdfWrapper if (!wrapper) return + + if (!useSmoothScroll) { + // 直接跳转到匹配位置,不做平滑滚动动画 + try { + target.scrollIntoView({ + behavior: 'auto', + block: 'center', + inline: 'nearest', + }) + } catch (e) { + // 兼容性兜底 + const container = target.closest('.pdf-page') || target + if (!container) return + const wrapperOffsetTop = container.offsetTop + const containerHeight = container.offsetHeight || target.offsetHeight || 0 + const desired = wrapperOffsetTop - Math.max((wrapper.clientHeight - containerHeight) / 2, 0) + this.cancelScrollAnimation() + wrapper.scrollTop = desired + } + return + } + const container = target.closest('.pdf-page') || target if (!container) return const wrapperOffsetTop = container.offsetTop const containerHeight = container.offsetHeight || target.offsetHeight || 0 const desired = wrapperOffsetTop - Math.max((wrapper.clientHeight - containerHeight) / 2, 0) - if (useSmoothScroll) { - this.smoothScrollTo(wrapper, desired) - } else { - this.cancelScrollAnimation() - wrapper.scrollTop = desired - } + this.smoothScrollTo(wrapper, desired) } if (useSmoothScroll) {