fix init of seasonals
This commit is contained in:
@ -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();
|
||||
|
Reference in New Issue
Block a user