From 36314e6391ca282712615e4a54a9fe31eae03236 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 21 Oct 2023 00:35:41 +0200 Subject: Only scroll to battle dialog if screen is small. --- play.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/play.js b/play.js index db11411..2a8ae7f 100644 --- a/play.js +++ b/play.js @@ -6,6 +6,12 @@ const svgNS = "http://www.w3.org/2000/svg" const round = Math.round const sqrt = Math.sqrt +function scroll_into_view_if_mobile(e) { + // if ("ontouchstart" in window) + if (window.innerWidth <= 800) + e.scrollIntoView({ block: "center", inline: "center", behavior: "smooth" }) +} + // refit and queue hexes const MALTA = 4 const hex_special = [ 47, 48, 49, 53, 102, 127, MALTA ] @@ -938,7 +944,7 @@ function update_battle_line(hex, line, test) { function update_battle() { if (ui.battle.classList.contains("hide")) { ui.battle.classList.remove("hide") - ui.battle.scrollIntoView({ block: "center", inline: "center", behavior: "smooth" }) + scroll_into_view_if_mobile(ui.battle) } ui.battle_header.textContent = hex_name[view.battle] @@ -967,8 +973,7 @@ function update_battle() { function update_pursuit() { if (ui.pursuit.classList.contains("hide")) { ui.pursuit.classList.remove("hide") - ui.pursuit.scrollIntoView({ block: "center", inline: "center", behavior: "smooth" }) - + scroll_into_view_if_mobile(ui.pursuit) } ui.pursuit_header.textContent = "Pursuit Fire at " + hex_name[view.pursuit] ui.pursuit_message.textContent = view.flash -- cgit v1.2.3