Skip to content

Commit

Permalink
Create main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
melonmasteristaken authored Jun 4, 2024
1 parent 149b57d commit 210815b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fireflies = document.querySelector('.fireflies');

for (let i = 0; i < 12; i++) { // Create 10 fireflies
const firefly = document.createElement('div');
firefly.classList.add('firefly');
firefly.style.top = `${random(-200, 200)}px`;
firefly.style.left = `${random(-200, 200)}px`;
firefly.style.animationDelay = `${random(0, 2)}s`;

// Add movement animation
firefly.animate([
{ top: `${random(-200, 200)}px`, left: `${random(-200, 200)}px` },
{ top: `${random(-200, 200)}px`, left: `${random(-200, 200)}px` }
], {
duration: 2000, // 2 seconds
iterations: Infinity, // Repeat indefinitely
easing: 'ease-out' // Smooth animation
});

fireflies.appendChild(firefly);
}

function random(min, max) {
return Math.random() * (max - min) + min;
}

0 comments on commit 210815b

Please sign in to comment.