From e051dbc2c73b9b4a14110d6a2b3632df9d8feac6 Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Sat, 18 Feb 2023 00:00:00 -0800 Subject: [PATCH] Fix autoscroll behavior for the first image When the first image is generated, the autoscroll triggers before the image is fully displayed by the browser. This causes it to not be positioned properly. The fix is to listen for the "load" event on the IMG element before triggering the scrolling event. Once the image fully loaded and rendered, the browser correctly detects the size of the viewport and renders properly. --- ui/plugins/ui/Autoscroll.plugin.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/plugins/ui/Autoscroll.plugin.js b/ui/plugins/ui/Autoscroll.plugin.js index 72905c6d..24818ce2 100644 --- a/ui/plugins/ui/Autoscroll.plugin.js +++ b/ui/plugins/ui/Autoscroll.plugin.js @@ -39,7 +39,10 @@ function Autoscroll(target) { if (autoScroll.checked && target !== null) { - target.parentElement.parentElement.parentElement.scrollIntoView(); + const img = target.querySelector('img') + img.addEventListener('load', function() { + img.closest('.imageTaskContainer').scrollIntoView() + }, { once: true }) } } })()