30 lines
No EOL
1,015 B
TypeScript
30 lines
No EOL
1,015 B
TypeScript
function createSnowflakes() {
|
|
const numSnowflakes = 50;
|
|
const maxSize = 0.2;
|
|
const maxTranslate = 10;
|
|
const container = document.getElementById('snowflake-container');
|
|
|
|
function randomBetween(min, max) {
|
|
return (Math.random() * max) + min;
|
|
}
|
|
|
|
if (container) {
|
|
for (let i = 0; i < numSnowflakes; i++) {
|
|
let randomSize = randomBetween(5, 25) + "px";
|
|
let randomLeft = randomBetween(0, window.innerWidth) + "px";
|
|
let randomDuration = randomBetween(3, 10);
|
|
|
|
const snowflake = document.createElement('div');
|
|
snowflake.classList.add('snowflake');
|
|
snowflake.style.width = randomSize;
|
|
snowflake.style.height = randomSize;
|
|
snowflake.style.left = randomLeft;
|
|
snowflake.style.animationDuration = randomDuration + "s";
|
|
snowflake.style.animationDelay = randomBetween(0, 5) + "s";
|
|
|
|
container.appendChild(snowflake);
|
|
}
|
|
}
|
|
}
|
|
|
|
createSnowflakes(); |