From 81ed9fa891753ae9a8e090277a15762b03ec6a05 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sat, 25 Dec 2021 11:51:28 +0100 Subject: More compact snowfall --- content/script.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'content') diff --git a/content/script.js b/content/script.js index 78b18b0..dd7729d 100644 --- a/content/script.js +++ b/content/script.js @@ -2,22 +2,21 @@ 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"); snowFlake.classList.add("o-icon", "o-icon--snow"); snowFlake.setAttribute("aria-hidden", "true"); snowFlake.style.fontSize = Math.random() * 0.5 + 0.7 + 'em'; - snowFlake.style.left = Math.random() * window.innerWidth + 'px'; - snowFlake.style.animationDuration = aniDuration + 'ms'; + snowFlake.style.left = Math.random() * 100 + '%'; + snowFlake.style.animationDuration = (Math.random() * 3 + 2) * 1000 + 'ms'; snowFlake.style.opacity = Math.random(); + + snowFlake.addEventListener("animationend", () => snowFlake.remove()); snowFlake.appendChild(snowFlakeInner); document.body.appendChild(snowFlake); - setTimeout(() => snowFlake.remove(), aniDuration); setTimeout(() => createSnowFlake(), 50 / Math.log10(window.innerWidth / 1000 + 1)); } -- cgit v1.2.3-54-g00ecf