From 65a63deb9b939b8f18c81386ed369a4232811ad8 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Tue, 28 Dec 2021 13:26:25 +0100 Subject: Use timeout to remove snowflake --- content/script.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/content/script.js b/content/script.js index 763734e..fd275b6 100644 --- a/content/script.js +++ b/content/script.js @@ -7,6 +7,7 @@ function createSnowFlake() { const snowFlake = document.createElementNS("http://www.w3.org/2000/svg", "svg"); const snowFlakeInner = document.createElementNS("http://www.w3.org/2000/svg", "use"); + const aniDuration = (Math.random() * 3 + 2) * 1000; snowFlakeInner.setAttribute("href", "/symbols.svg#icon-asterisk"); @@ -15,10 +16,10 @@ function createSnowFlake() { snowFlake.style.fontSize = Math.random() * 0.5 + 0.7 + 'em'; snowFlake.style.left = Math.random() * 100 + '%'; - snowFlake.style.animationDuration = (Math.random() * 3 + 2) * 1000 + 'ms'; + snowFlake.style.animationDuration = aniDuration + 'ms'; snowFlake.style.opacity = Math.random(); - snowFlake.addEventListener("animationend", () => snowFlake.remove()); + setTimeout(() => snowFlake.remove(), aniDuration); snowFlake.appendChild(snowFlakeInner); document.body.appendChild(snowFlake); -- cgit v1.2.3-54-g00ecf