add random duration
This commit is contained in:
18
autumn.js
18
autumn.js
@@ -1,6 +1,7 @@
|
|||||||
const leaves = true; // enable/disable leaves
|
const leaves = true; // enable/disable leaves
|
||||||
const randomLeaves = true; // enable random leaves
|
const randomLeaves = true; // enable random leaves
|
||||||
const randomLeavesMobile = false; // enable random leaves on mobile devices
|
const randomLeavesMobile = false; // enable random leaves on mobile devices
|
||||||
|
const enableDiffrentDuration = true; // enable different duration for the random leaves
|
||||||
const leafCount = 25; // count of random extra leaves
|
const leafCount = 25; // count of random extra leaves
|
||||||
|
|
||||||
|
|
||||||
@@ -115,9 +116,12 @@ 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)
|
// set random animation duration
|
||||||
const randomAnimationDuration2 = Math.random() * 5 + 2; // delay (2s to 5s)
|
if (enableDiffrentDuration) {
|
||||||
leafDiv.style.animationDuration = `${randomAnimationDuration}s, ${randomAnimationDuration2}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);
|
||||||
@@ -143,9 +147,11 @@ function initLeaves() {
|
|||||||
img.src = images[Math.floor(Math.random() * images.length)];
|
img.src = images[Math.floor(Math.random() * images.length)];
|
||||||
|
|
||||||
// set random animation duration
|
// set random animation duration
|
||||||
const randomAnimationDuration = Math.random() * 10 + 6; // delay (6s to 10s)
|
if (enableDiffrentDuration) {
|
||||||
const randomAnimationDuration2 = Math.random() * 5 + 2; // delay (2s to 5s)
|
const randomAnimationDuration = Math.random() * 10 + 6; // delay (6s to 10s)
|
||||||
leafDiv.style.animationDuration = `${randomAnimationDuration}s, ${randomAnimationDuration2}s`;
|
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);
|
||||||
|
Reference in New Issue
Block a user