pdf 搜索优化

This commit is contained in:
cwchen 2025-11-27 18:44:18 +08:00
parent a5b156a7be
commit ed03901ba8
1 changed files with 23 additions and 6 deletions

View File

@ -823,17 +823,34 @@ export default {
if (!target) return if (!target) return
const wrapper = this.$refs.pdfWrapper const wrapper = this.$refs.pdfWrapper
if (!wrapper) return if (!wrapper) return
if (!useSmoothScroll) {
//
try {
target.scrollIntoView({
behavior: 'auto',
block: 'center',
inline: 'nearest',
})
} catch (e) {
//
const container = target.closest('.pdf-page') || target const container = target.closest('.pdf-page') || target
if (!container) return if (!container) return
const wrapperOffsetTop = container.offsetTop const wrapperOffsetTop = container.offsetTop
const containerHeight = container.offsetHeight || target.offsetHeight || 0 const containerHeight = container.offsetHeight || target.offsetHeight || 0
const desired = wrapperOffsetTop - Math.max((wrapper.clientHeight - containerHeight) / 2, 0) const desired = wrapperOffsetTop - Math.max((wrapper.clientHeight - containerHeight) / 2, 0)
if (useSmoothScroll) {
this.smoothScrollTo(wrapper, desired)
} else {
this.cancelScrollAnimation() this.cancelScrollAnimation()
wrapper.scrollTop = desired 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)
this.smoothScrollTo(wrapper, desired)
} }
if (useSmoothScroll) { if (useSmoothScroll) {