diff --git a/code/websites/pokedex.online/src/views/GamemasterExplorer.vue b/code/websites/pokedex.online/src/views/GamemasterExplorer.vue index 8f2ee13..53396ad 100644 --- a/code/websites/pokedex.online/src/views/GamemasterExplorer.vue +++ b/code/websites/pokedex.online/src/views/GamemasterExplorer.vue @@ -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) {