diff --git a/app/src/util/highlightById.ts b/app/src/util/highlightById.ts index 7f4cd9259..1ef92d030 100644 --- a/app/src/util/highlightById.ts +++ b/app/src/util/highlightById.ts @@ -111,14 +111,15 @@ export const scrollCenter = ( } if (position === "nearest") { // 在可视区域内不进行滚动 - if (elementRect.top < contentRect.top) { + if (elementRect.bottom < contentRect.top) { protyle.contentElement.scroll({ top: protyle.contentElement.scrollTop + elementRect.top - contentRect.top, behavior }); - } else if (elementRect.bottom > contentRect.bottom) { + } else if (elementRect.top > contentRect.bottom) { protyle.contentElement.scroll({ - top: protyle.contentElement.scrollTop + elementRect.bottom - contentRect.bottom, + top: elementRect.height > contentRect.height ? protyle.contentElement.scrollTop + elementRect.top - contentRect.top : + protyle.contentElement.scrollTop + elementRect.bottom - contentRect.bottom, behavior }); }