🎯 Improve scroll-to-result logic for centering elements within containers

This commit is contained in:
2026-01-28 21:14:11 +00:00
parent 5584dd8502
commit 9507c7b304

View File

@@ -764,16 +764,14 @@ function scrollToResult() {
// Scroll only within the container, not the whole page
const container = lineElement.closest('.scroller, .lines-container');
if (container) {
const containerRect = container.getBoundingClientRect();
const elementRect = lineElement.getBoundingClientRect();
// Get element's position relative to the container
const elementOffsetTop = lineElement.offsetTop;
const containerHeight = container.clientHeight;
const elementHeight = lineElement.offsetHeight;
// Calculate scroll position to center element in container
const scrollOffset =
elementRect.top -
containerRect.top -
containerRect.height / 2 +
elementRect.height / 2;
container.scrollBy({ top: scrollOffset, behavior: 'smooth' });
const scrollTo = elementOffsetTop - (containerHeight / 2) + (elementHeight / 2);
container.scrollTo({ top: scrollTo, behavior: 'smooth' });
}
return true;
} else if (attempt < 3) {