From 9507c7b304e3dc46b12e3d161d6876aed4bd77a5 Mon Sep 17 00:00:00 2001 From: FragginWagon Date: Wed, 28 Jan 2026 21:14:11 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=AF=20Improve=20scroll-to-result=20log?= =?UTF-8?q?ic=20for=20centering=20elements=20within=20containers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/GamemasterExplorer.vue | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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) {