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
|
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 to check and control the snowflakes
|
||||||
function toggleSnowflakes() {
|
function toggleSnowflakes() {
|
||||||
const snowflakeContainer = document.querySelector('.snowflakes');
|
const snowflakeContainer = document.querySelector('.snowflakes');
|
||||||
@@ -14,10 +16,16 @@ function toggleSnowflakes() {
|
|||||||
// hide snowflakes if video player is active or dashboard is visible
|
// hide snowflakes if video player is active or dashboard is visible
|
||||||
if (videoPlayer || isDashboard || hasUserMenu) {
|
if (videoPlayer || isDashboard || hasUserMenu) {
|
||||||
snowflakeContainer.style.display = 'none'; // hide snowflakes
|
snowflakeContainer.style.display = 'none'; // hide snowflakes
|
||||||
|
if (!msgPrinted) {
|
||||||
console.log('Snowflakes hidden');
|
console.log('Snowflakes hidden');
|
||||||
|
msgPrinted = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
snowflakeContainer.style.display = 'block'; // show snowflakes
|
snowflakeContainer.style.display = 'block'; // show snowflakes
|
||||||
|
if (msgPrinted) {
|
||||||
console.log('Snowflakes visible');
|
console.log('Snowflakes visible');
|
||||||
|
msgPrinted = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,20 +58,24 @@ function addRandomSnowflakes(count) {
|
|||||||
// set random horizontal position, size and animation delay
|
// set random horizontal position, size and animation delay
|
||||||
const randomLeft = Math.random() * 100; // position (0% to 100%)
|
const randomLeft = Math.random() * 100; // position (0% to 100%)
|
||||||
//const randomSize = Math.random() * 1.5 + 0.5; // size (0.5em to 2em)
|
//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
|
// apply styles
|
||||||
snowflake.style.left = `${randomLeft}%`;
|
snowflake.style.left = `${randomLeft}%`;
|
||||||
//snowflake.style.fontSize = `${randomSize}em`;
|
//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
|
// add the snowflake to the container
|
||||||
snowflakeContainer.appendChild(snowflake);
|
snowflakeContainer.appendChild(snowflake);
|
||||||
}
|
}
|
||||||
|
console.log('Random snowflakes added');
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize snowflakes
|
// initialize snowflakes
|
||||||
toggleSnowflakes(); //check if snowflakes should be hidden
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
toggleSnowflakes();
|
||||||
if (randomSnowflakes) {
|
if (randomSnowflakes) {
|
||||||
addRandomSnowflakes(snowflakeCount); //add random snowflakes
|
addRandomSnowflakes(snowflakeCount);
|
||||||
}
|
}
|
||||||
|
});
|
Reference in New Issue
Block a user