comments
This commit is contained in:
15
snowstorm.js
15
snowstorm.js
@@ -1,8 +1,10 @@
|
||||
const snowstorm = true; // enable/disable snowstorm
|
||||
const snowflakesCount = 500; // count of snowflakes
|
||||
const snowflakesCount = 500; // count of snowflakes (recommended values: 300-600)
|
||||
const snowFallSpeed = 4; // speed of snowfall (recommended values: 0-8)
|
||||
|
||||
let msgPrinted = false; // flag to prevent multiple console messages
|
||||
|
||||
// function to check and control the snowflakes
|
||||
// function to check and control the snowstorm
|
||||
function toggleSnowstorm() {
|
||||
const snowstormContainer = document.querySelector('.snow-container');
|
||||
if (!snowstormContainer) return;
|
||||
@@ -12,7 +14,7 @@ function toggleSnowstorm() {
|
||||
const isDashboard = document.body.classList.contains('dashboardDocument');
|
||||
const hasUserMenu = document.querySelector('#app-user-menu');
|
||||
|
||||
// hide snowflakes if video/trailer player is active or dashboard is visible
|
||||
// hide snowstorm if video/trailer player is active or dashboard is visible
|
||||
if (videoPlayer || trailerPlayer || isDashboard || hasUserMenu) {
|
||||
snowstormContainer.style.display = 'none'; // hide snowstorm
|
||||
if (!msgPrinted) {
|
||||
@@ -65,9 +67,9 @@ function createSnowstorm() {
|
||||
|
||||
function animateSnowflake(snowflake) {
|
||||
// animation parameters
|
||||
const fallSpeed = Math.random() * 5 + 2;
|
||||
const fallSpeed = Math.random() * snowFallSpeed + 2;
|
||||
const horizontalWind = Math.random() * 4 - 2;
|
||||
const verticalVariation = Math.random() * 2 - 1;
|
||||
const verticalVariation = Math.random() * 4 - 1;
|
||||
|
||||
function fall() {
|
||||
const currentTop = parseFloat(snowflake.style.top || 0);
|
||||
@@ -88,8 +90,7 @@ function animateSnowflake(snowflake) {
|
||||
fall();
|
||||
}
|
||||
|
||||
createSnowstorm();
|
||||
|
||||
// initialize snowstorm after the DOM is loaded
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
if (!snowstorm) return; // exit if snowstorm is disabled
|
||||
createSnowstorm();
|
||||
|
Reference in New Issue
Block a user