From e081c5ebaa788f22c57ee36b73ab7ed57ca7a562 Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Sun, 14 Nov 2021 23:27:56 +0100 Subject: [PATCH] Improve animation when changing tab --- base_rules.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/base_rules.js b/base_rules.js index da72320..038126e 100644 --- a/base_rules.js +++ b/base_rules.js @@ -2160,20 +2160,21 @@ export default class ChessRules { }; animateRec(0); }; - const checkDisplayThenAnimate = () => { + // Delay if user wasn't focused: + const checkDisplayThenAnimate = (delay) => { if (boardContainer.style.display == "none") { alert("New move! Let's go back to game..."); document.getElementById("gameInfos").style.display = "none"; boardContainer.style.display = "block"; setTimeout(launchAnimation, 700); } - else launchAnimation(); //focused user! + else setTimeout(launchAnimation, delay || 0); }; let boardContainer = document.getElementById("boardContainer"); if (document.hidden) { document.onvisibilitychange = () => { document.onvisibilitychange = undefined; - checkDisplayThenAnimate(); + checkDisplayThenAnimate(700); }; } else checkDisplayThenAnimate(); -- 2.44.0