From 2aba723ac4453b99a9b86e403aea4cc24fbd8dba Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 20 May 2020 15:57:54 +0100 Subject: [PATCH] fixed word restart transition not being smooth and sometimes not showing words at all --- public/js/script.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/public/js/script.js b/public/js/script.js index 1e6266b12..bb6ff6c08 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -533,15 +533,7 @@ function showResult() { wpmOverTimeChart.data.labels = labels; wpmOverTimeChart.data.datasets[0].data = wpmHistory; wpmOverTimeChart.update({ duration: 0 }); - $("#words").animate({ - opacity: 0 - }, 125, () => { - $("#words").addClass('hidden'); - $("#result").css('opacity', 0).removeClass('hidden'); - $("#result").animate({ - opacity: 1 - }, 125); - }) + swapElements($("#words"),$("#result"),250); } function restartTest() { @@ -552,8 +544,17 @@ function restartTest() { hideCaret(); testActive = false; hideLiveWpm(); - $("#words").stop(true, true).animate({ opacity: 0 }, 125); - $("#result").stop(true, true).animate({ + + let el = null; + if($("#words").hasClass('hidden')){ + //results are being displayed + el = $("#result"); + }else if($("#result").hasClass('hidden')){ + //words are being displayed + el = $("#words"); + } + + el.stop(true, true).animate({ opacity: 0 }, 125, () => { initWords();