show log only once, add random after dom loaded
This commit is contained in:
@@ -2,6 +2,8 @@ const randomSnowflakes = false; // enable random Snowflakes
|
||||
const snowflakeCount = 50; // count of random extra snowflakes
|
||||
|
||||
|
||||
let msgPrinted = false; // flag to prevent multiple console messages
|
||||
|
||||
// function to check and control the snowflakes
|
||||
function toggleSnowflakes() {
|
||||
const snowflakeContainer = document.querySelector('.snowflakes');
|
||||
@@ -14,10 +16,16 @@ function toggleSnowflakes() {
|
||||
// hide snowflakes if video player is active or dashboard is visible
|
||||
if (videoPlayer || isDashboard || hasUserMenu) {
|
||||
snowflakeContainer.style.display = 'none'; // hide snowflakes
|
||||
if (!msgPrinted) {
|
||||
console.log('Snowflakes hidden');
|
||||
msgPrinted = true;
|
||||
}
|
||||
} else {
|
||||
snowflakeContainer.style.display = 'block'; // show snowflakes
|
||||
if (msgPrinted) {
|
||||
console.log('Snowflakes visible');
|
||||
msgPrinted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,20 +58,24 @@ function addRandomSnowflakes(count) {
|
||||
// set random horizontal position, size and animation delay
|
||||
const randomLeft = Math.random() * 100; // position (0% to 100%)
|
||||
//const randomSize = Math.random() * 1.5 + 0.5; // size (0.5em to 2em)
|
||||
const randomAnimationDelay = Math.random() * 5; // delay (0s to 5s)
|
||||
const randomAnimationDelay = Math.random() * 8; // delay (0s to 8s)
|
||||
const randomAnimationDelay2 = Math.random() * 5; // delay (0s to 5s)
|
||||
|
||||
// apply styles
|
||||
snowflake.style.left = `${randomLeft}%`;
|
||||
//snowflake.style.fontSize = `${randomSize}em`;
|
||||
snowflake.style.animationDelay = `${randomAnimationDelay}s, ${randomAnimationDelay / 2}s`;
|
||||
snowflake.style.animationDelay = `${randomAnimationDelay}s, ${randomAnimationDelay2}s`;
|
||||
|
||||
// add the snowflake to the container
|
||||
snowflakeContainer.appendChild(snowflake);
|
||||
}
|
||||
console.log('Random snowflakes added');
|
||||
}
|
||||
|
||||
// initialize snowflakes
|
||||
toggleSnowflakes(); //check if snowflakes should be hidden
|
||||
if (randomSnowflakes) {
|
||||
addRandomSnowflakes(snowflakeCount); //add random snowflakes
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
toggleSnowflakes();
|
||||
if (randomSnowflakes) {
|
||||
addRandomSnowflakes(snowflakeCount);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user