« get me outta code hell

scroll autoloaded target into view - kinda - scratchblocks-generator-3 - scratchblocks generator for projects made in 3.0
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2019-12-20 17:58:39 -0400
committerFlorrie <towerofnix@gmail.com>2019-12-20 17:58:39 -0400
commit763b8f5777c1ff23114057c40d8b746ef73f21d9 (patch)
tree11b0d5e17932932a008cf988294f8c3e0a814cc7
parent54906d097f518b95e9301606fa7807a777474bda (diff)
scroll autoloaded target into view - kinda
-rw-r--r--src/js/main.js10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/js/main.js b/src/js/main.js
index 3a3f823..f7ad5f4 100644
--- a/src/js/main.js
+++ b/src/js/main.js
@@ -172,7 +172,15 @@ function presentTarget(targetName) {
     for (const el of document.querySelectorAll('.target.selected')) {
         el.classList.remove('selected');
     }
-    document.querySelector(`.target[data-name="${targetName.replace(/"/g, '\\"')}"]`).classList.add('selected');
+    const el = document.querySelector(`.target[data-name="${targetName.replace(/"/g, '\\"')}"]`);
+    el.classList.add('selected');
+    // XXX: this is a hack! we wait 100ms as a guard so that we _probably_ run scrollIntoView after
+    // any images have loaded. however, this doesn't work if the images don't load within that
+    // time, in which case the element will not properly be scrolled into view (the loaded images
+    // will push it out of the way). to deal with this, we should wait until all images positioned
+    // before this target's element have loaded (but we should also make sure to skip images that
+    // have already loaded).
+    setTimeout(() => el.scrollIntoView(), 100);
 
     clearChildren(scriptArea);
     if (target.scripts.length) {