summaryrefslogtreecommitdiff
path: root/app/views/game
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-06-23 20:20:21 -0400
committerDavid Gay <david@davidgay.org>2021-06-23 20:23:00 -0400
commitc608468b7d6dad0a007ce1031724737b02fbdd55 (patch)
tree23f07975ec0a3afe3015c6196d63b59256b715c1 /app/views/game
parent5fde28051b17e0f498bc9bb09666c2567d4c776a (diff)
Fix results and chat divs sometimes not scrolling due to large output
Diffstat (limited to 'app/views/game')
-rw-r--r--app/views/game/finish_activity.js.erb10
1 files changed, 8 insertions, 2 deletions
diff --git a/app/views/game/finish_activity.js.erb b/app/views/game/finish_activity.js.erb
index fa3d228..f281986 100644
--- a/app/views/game/finish_activity.js.erb
+++ b/app/views/game/finish_activity.js.erb
@@ -4,10 +4,16 @@ var resultControlsDiv = document.getElementById("activity_controls");
var outputHTML = "<%= j render(partial: "application/results", locals: { results: @results }) %>"
if (resultOutputDiv) {
- resultOutputDiv.innerHTML += outputHTML;
-
// If scrolled to the bottom or near the bottom, then smooth scroll to the bottom.
+ // (Check before adding output, because a large output could prevent the scroll when it shouldn't.)
+ var shouldScroll = false;
if ((resultOutputDiv.scrollTop + 100) >= (resultOutputDiv.scrollHeight - resultOutputDiv.offsetHeight)) {
+ shouldScroll = true;
+ }
+
+ resultOutputDiv.innerHTML += outputHTML;
+
+ if (shouldScroll) {
resultOutputDiv.scrollTo({
top: resultOutputDiv.scrollHeight, left: 0, behavior: 'smooth'
});