From: Benjamin Auder Date: Sun, 14 Nov 2021 22:27:56 +0000 (+0100) Subject: Improve animation when changing tab X-Git-Url: https://git.auder.net/variants/current/doc/scripts/img/index.css?a=commitdiff_plain;h=e081c5ebaa788f22c57ee36b73ab7ed57ca7a562;p=xogo.git Improve animation when changing tab --- 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();