fix init of seasonals

This commit is contained in:
MLH
2024-12-22 01:51:51 +01:00
parent 0071be6570
commit d5c697afdf
8 changed files with 55 additions and 70 deletions

View File

@ -80,27 +80,25 @@ function animateSnowflake(snowflake) {
const sidewaysMovement = Math.random() * 2 - 1;
function fall() {
const currentTop = parseFloat(snowflake.style.top || 0);
const currentLeft = parseFloat(snowflake.style.left || 0);
const currentTop = parseFloat(snowflake.style.top || 0);
const currentLeft = parseFloat(snowflake.style.left || 0);
// fall and sideways movement
snowflake.style.top = `${currentTop + speed}px`;
snowflake.style.left = `${currentLeft + sidewaysMovement}px`;
// fall and sideways movement
snowflake.style.top = `${currentTop + speed}px`;
snowflake.style.left = `${currentLeft + sidewaysMovement}px`;
// if snowflake is out of the window, reset its position
if (currentTop > window.innerHeight) {
snowflake.style.top = '0px';
snowflake.style.left = `${Math.random() * window.innerWidth}px`;
}
// if snowflake is out of the window, reset its position
if (currentTop > window.innerHeight) {
snowflake.style.top = '0px';
snowflake.style.left = `${Math.random() * window.innerWidth}px`;
}
requestAnimationFrame(fall);
requestAnimationFrame(fall);
}
fall();
}
// initialize snowfall after the DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
if (!snowfall) return; // exit if snowfall is disabled
createSnowflakes();
});
if (!snowfall) return; // exit if snowfall is disabled
createSnowflakes();