🎯 Improve scroll-to-result logic for centering elements within containers
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user