some fixes
This commit is contained in:
20
fireworks.js
20
fireworks.js
@@ -1,10 +1,10 @@
|
||||
const fireworks = true; // enable/disable fireworks
|
||||
const particlesPerFirework = 30; // count of particles per firework
|
||||
const particlesPerFirework = 50; // count of particles per firework
|
||||
|
||||
let msgPrinted = false; // flag to prevent multiple console messages
|
||||
|
||||
// function to check and control fireworks
|
||||
function toggleSnowflakes() {
|
||||
function toggleFirework() {
|
||||
const fireworksContainer = document.querySelector('.fireworks');
|
||||
if (!fireworksContainer) return;
|
||||
|
||||
@@ -30,7 +30,7 @@ function toggleSnowflakes() {
|
||||
}
|
||||
|
||||
// observe changes in the DOM
|
||||
const observer = new MutationObserver(toggleSnowflakes);
|
||||
const observer = new MutationObserver(toggleFirework);
|
||||
|
||||
// start observation
|
||||
observer.observe(document.body, {
|
||||
@@ -45,8 +45,9 @@ function launchFirework() {
|
||||
if (!fireworkContainer) return;
|
||||
|
||||
// random position on the screen
|
||||
const x = Math.random() * window.innerWidth;
|
||||
const y = Math.random() * window.innerHeight;
|
||||
const x = Math.random() * window.innerWidth * 0.8 + window.innerWidth * 0.1;
|
||||
const y = Math.random() * window.innerHeight * 0.7 + window.innerHeight * 0.15;
|
||||
|
||||
|
||||
// create particles for the firework
|
||||
for (let i = 0; i < particlesPerFirework; i++) {
|
||||
@@ -55,7 +56,7 @@ function launchFirework() {
|
||||
|
||||
// random angle and distance
|
||||
const angle = Math.random() * 2 * Math.PI; // 0 to 360 degrees
|
||||
const distance = Math.random() * 100 + 50; // 50 to 150 pixels
|
||||
const distance = Math.random() * 150 + 100; // 50 to 150 pixels
|
||||
const xOffset = Math.cos(angle) * distance;
|
||||
const yOffset = Math.sin(angle) * distance;
|
||||
|
||||
@@ -78,8 +79,11 @@ function launchFirework() {
|
||||
// automaticly start fireworks
|
||||
function startFireworks() {
|
||||
setInterval(() => {
|
||||
launchFirework();
|
||||
}, 1000); // firework every second
|
||||
const randomCount = Math.random() * 3 + 2; // 2 to 5 fireworks simultaneously
|
||||
for (let i = 0; i < randomCount; i++) {
|
||||
launchFirework();
|
||||
}
|
||||
}, 600); // firework every 600 mil second
|
||||
}
|
||||
|
||||
// initialize snowflakes and add random snowflakes after the DOM is loaded
|
||||
|
Reference in New Issue
Block a user