pdf 搜索优化
This commit is contained in:
parent
a5b156a7be
commit
ed03901ba8
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue