Vanessa 2025-12-14 19:57:09 +08:00
parent 9156aee244
commit b0f674d84c

View file

@ -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
});
}