add random duration

This commit is contained in:
MLH
2024-12-21 23:52:22 +01:00
parent 139f4e6e43
commit f33c3389be

View File

@ -115,6 +115,10 @@ function addRandomLeaves(count) {
leaveDiv.style.left = `${randomLeft}%`; leaveDiv.style.left = `${randomLeft}%`;
leaveDiv.style.animationDelay = `${randomAnimationDelay}s, ${randomAnimationDelay2}s`; 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 // add the leave to the container
autumnContainer.appendChild(leaveDiv); autumnContainer.appendChild(leaveDiv);
} }
@ -138,6 +142,11 @@ function initLeaves() {
const img = document.createElement("img"); const img = document.createElement("img");
img.src = images[Math.floor(Math.random() * images.length)]; 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); leafDiv.appendChild(img);
container.appendChild(leafDiv); container.appendChild(leafDiv);
} }