fix random
This commit is contained in:
17
halloween.js
17
halloween.js
@@ -87,11 +87,16 @@ function addRandomSymbols(count) {
|
|||||||
|
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
// create a new halloween elements
|
// create a new halloween elements
|
||||||
const halloween = document.createElement('div');
|
const halloweenDiv = document.createElement("div");
|
||||||
halloween.classList.add('halloween');
|
halloweenDiv.className = "halloween";
|
||||||
|
|
||||||
// pick a random halloween symbol
|
// pick a random halloween symbol
|
||||||
halloween.textContent = images[Math.floor(Math.random() * images.length)];
|
const imageSrc = images[Math.floor(Math.random() * images.length)];
|
||||||
|
const img = document.createElement("img");
|
||||||
|
img.src = imageSrc;
|
||||||
|
|
||||||
|
halloweenDiv.appendChild(img);
|
||||||
|
|
||||||
|
|
||||||
// set random horizontal position, animation delay and size(uncomment lines to enable)
|
// set random horizontal position, animation delay and size(uncomment lines to enable)
|
||||||
const randomLeft = Math.random() * 100; // position (0% to 100%)
|
const randomLeft = Math.random() * 100; // position (0% to 100%)
|
||||||
@@ -100,11 +105,11 @@ function addRandomSymbols(count) {
|
|||||||
const randomAnimationDelay2 = Math.random() * 5; // delay (0s to 5s)
|
const randomAnimationDelay2 = Math.random() * 5; // delay (0s to 5s)
|
||||||
|
|
||||||
// apply styles
|
// apply styles
|
||||||
halloween.style.left = `${randomLeft}%`;
|
halloweenDiv.style.left = `${randomLeft}%`;
|
||||||
halloween.style.animationDelay = `${randomAnimationDelay}s, ${randomAnimationDelay2}s`;
|
halloweenDiv.style.animationDelay = `${randomAnimationDelay}s, ${randomAnimationDelay2}s`;
|
||||||
|
|
||||||
// add the halloween to the container
|
// add the halloween to the container
|
||||||
halloweenContainer.appendChild(halloween);
|
halloweenContainer.appendChild(halloweenDiv);
|
||||||
}
|
}
|
||||||
console.log('Random halloween symbols added');
|
console.log('Random halloween symbols added');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user