This commit is contained in:
MLH
2024-11-24 22:42:13 +01:00
parent 737a7dfde6
commit 077302e181
3 changed files with 32 additions and 64 deletions

View File

@@ -1,19 +1,21 @@
let randomSnowflakes = flase; // enable random Snowflakes
const randomSnowflakes = flase; // enable random Snowflakes
const snowflakeCount = 50; // count of random extra snowflakes
// function to check and control the snowflakes
function toggleSnowflakes() {
const body = document.body;
const snowflakeContainer = document.querySelector('.snowflakes');
if (!snowflakeContainer) return;
const videoPlayer = document.querySelector('.videoPlayerContainer');
const isDashboard = body.classList.contains('dashboardDocument');
const isDashboard = document.body.classList.contains('dashboardDocument');
const hasUserMenu = document.querySelector('#app-user-menu');
// hide snowflakes if video player is active or dashboard is visible
if (videoPlayer || isDashboard || hasUserMenu) {
body.classList.add('hide-snowflakes');
snowflakeContainer.style.display = 'none'; // hide snowflakes
} else {
body.classList.remove('hide-snowflakes');
snowflakeContainer.style.display = 'block'; // show snowflakes
}
}
@@ -34,32 +36,30 @@ function addRandomSnowflakes(count) {
const snowflakeSymbols = ['❅', '❆', '❄']; // some snowflake symbols
for (let i = 0; i < count; i++) {
// create a new snowflake element
const snowflake = document.createElement('div');
snowflake.classList.add('snowflake');
// create a new snowflake element
const snowflake = document.createElement('div');
snowflake.classList.add('snowflake');
// pick a random snowflake symbol
snowflake.textContent = snowflakeSymbols[Math.floor(Math.random() * snowflakeSymbols.length)];
// pick a random snowflake symbol
snowflake.textContent = snowflakeSymbols[Math.floor(Math.random() * snowflakeSymbols.length)];
// 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)
// 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)
// apply styles
snowflake.style.left = `${randomLeft}%`;
snowflake.style.fontSize = `${randomSize}em`;
snowflake.style.animationDelay = `${randomAnimationDelay}s, ${randomAnimationDelay / 2}s`;
// apply styles
snowflake.style.left = `${randomLeft}%`;
//snowflake.style.fontSize = `${randomSize}em`;
snowflake.style.animationDelay = `${randomAnimationDelay}s, ${randomAnimationDelay / 2}s`;
// add the snowflake to the container
snowflakeContainer.appendChild(snowflake);
// add the snowflake to the container
snowflakeContainer.appendChild(snowflake);
}
}
// initialize snowflakes
document.addEventListener('DOMContentLoaded', () => {
toggleSnowflakes(); //check if snowflakes should be hidden
if (randomSnowflakes) {
addRandomSnowflakes(snowflakeCount); //add random snowflakes
}
});
toggleSnowflakes(); //check if snowflakes should be hidden
if (randomSnowflakes) {
addRandomSnowflakes(snowflakeCount); //add random snowflakes
}