on mobile less snowflakes

This commit is contained in:
MLH
2025-01-13 23:52:36 +01:00
parent 771e93f875
commit 9d9476d0fc
2 changed files with 12 additions and 1 deletions

View File

@ -1,5 +1,6 @@
const snowfall = true; // enable/disable snowfall
const snowflakesCount = 500; // count of snowflakes (recommended values: 300-600)
const snowflakesCountMobile = 300; // count of snowflakes on mobile devices
const snowFallSpeed = 3; // speed of snowfall (recommended values: 0-5)
let msgPrinted = false; // flag to prevent multiple console messages
@ -118,12 +119,17 @@ function animateSnowfall() {
// initialize snowfall
function initializeSnowfall() {
if (!snowfall){
if (!snowfall) {
console.warn('Snowfall is disabled.');
return; // exit if snowfall is disabled
}
const container = document.querySelector('.snowfall-container');
if (container) {
const screenWidth = window.innerWidth; // get the screen width to detect mobile devices
if (screenWidth < 768) { // lower count of snowflakes on mobile devices
snowflakesCount = snowflakesCountMobile;
}
console.log('Snowfall enabled.');
initializeCanvas();
snowflakes = createSnowflakes(container);

View File

@ -124,6 +124,11 @@ document.addEventListener('DOMContentLoaded', () => {
}
const container = document.querySelector('.snowfall-container');
if (container) {
const screenWidth = window.innerWidth; // get the screen width to detect mobile devices
if (screenWidth < 768) { // lower count of snowflakes on mobile devices
snowflakesCount = snowflakesCountMobile;
}
console.log('Snowfall enabled.');
initializeCanvas();
snowflakes = createSnowflakes(container);