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.
This commit is contained in:
patriceac 2023-02-18 00:00:00 -08:00 committed by GitHub
parent 1050b13bbb
commit e051dbc2c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,7 +39,10 @@
function Autoscroll(target) { function Autoscroll(target) {
if (autoScroll.checked && target !== null) { 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 })
} }
} }
})() })()