From f33c3389bea25ab0c542dcc1030ac018db37d5db Mon Sep 17 00:00:00 2001 From: CodeDevMLH Date: Sat, 21 Dec 2024 23:52:22 +0100 Subject: [PATCH] add random duration --- autumn.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/autumn.js b/autumn.js index 6166753..feceb29 100644 --- a/autumn.js +++ b/autumn.js @@ -115,6 +115,10 @@ function addRandomLeaves(count) { leaveDiv.style.left = `${randomLeft}%`; leaveDiv.style.animationDelay = `${randomAnimationDelay}s, ${randomAnimationDelay2}s`; + const randomAnimationDuration = Math.random() * 10 + 6; // delay (6s to 10s) + const randomAnimationDuration2 = Math.random() * 5 + 2; // delay (2s to 5s) + leafDiv.style.animationDuration = `${randomAnimationDuration}s, ${randomAnimationDuration2}s`; + // add the leave to the container autumnContainer.appendChild(leaveDiv); } @@ -138,6 +142,11 @@ function initLeaves() { const img = document.createElement("img"); img.src = images[Math.floor(Math.random() * images.length)]; + // set random animation duration + const randomAnimationDuration = Math.random() * 10 + 6; // delay (6s to 10s) + const randomAnimationDuration2 = Math.random() * 5 + 2; // delay (2s to 5s) + leafDiv.style.animationDuration = `${randomAnimationDuration}s, ${randomAnimationDuration2}s`; + leafDiv.appendChild(img); container.appendChild(leafDiv); }