-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Celebration Button</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<button id="celebrateButton" class="party-popper">🎉</button> | ||
<canvas id="confettiCanvas"></canvas> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const button = document.getElementById('celebrateButton'); | ||
const canvas = document.getElementById('confettiCanvas'); | ||
const context = canvas.getContext('2d'); | ||
const confettiElements = []; | ||
let isCelebrating = false; | ||
let animationFrameId; | ||
|
||
// Set canvas size | ||
canvas.width = window.innerWidth; | ||
canvas.height = window.innerHeight; | ||
|
||
class Confetti { | ||
constructor(x, y) { | ||
this.x = x; | ||
this.y = y; | ||
this.size = Math.random() * 10 + 5; | ||
this.speed = 3.1; // Constant speed | ||
this.angle = Math.random() * 360; | ||
this.color = `hsl(${Math.random() * 360}, 100%, 50%)`; | ||
} | ||
|
||
update() { | ||
this.y += this.speed; | ||
this.angle += this.speed; | ||
if (this.y > canvas.height) { | ||
this.y = -10; | ||
this.x = Math.random() * canvas.width; | ||
} | ||
} | ||
|
||
draw() { | ||
context.fillStyle = this.color; | ||
context.beginPath(); | ||
context.ellipse(this.x, this.y, this.size, this.size / 2, this.angle, 0, 2 * Math.PI); | ||
context.fill(); | ||
} | ||
} | ||
|
||
function addConfetti() { | ||
for (let i = 0; i < 100; i++) { | ||
confettiElements.push(new Confetti(Math.random() * canvas.width, Math.random() * canvas.height)); | ||
} | ||
} | ||
|
||
function animate() { | ||
context.clearRect(0, 0, canvas.width, canvas.height); | ||
confettiElements.forEach(confetti => { | ||
confetti.update(); | ||
confetti.draw(); | ||
}); | ||
animationFrameId = requestAnimationFrame(animate); | ||
} | ||
|
||
function toggleConfetti() { | ||
if (isCelebrating) { | ||
// Stop the confetti | ||
cancelAnimationFrame(animationFrameId); | ||
context.clearRect(0, 0, canvas.width, canvas.height); | ||
confettiElements.length = 0; // Clear confetti elements | ||
} else { | ||
// Start the confetti | ||
addConfetti(); | ||
animate(); | ||
} | ||
isCelebrating = !isCelebrating; | ||
} | ||
|
||
button.addEventListener('click', toggleConfetti); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
body, html { | ||
margin: 0; | ||
padding: 0; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
background-color: #f0f0f0; | ||
|
||
} | ||
|
||
.container { | ||
position: static; | ||
} | ||
|
||
.party-popper { | ||
background-color: #ffcc00; | ||
border: none; | ||
border-radius: 50%; | ||
width: 100px; | ||
height: 100px; | ||
font-size: 2rem; | ||
cursor: pointer; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); | ||
transition: transform 0.2s; | ||
} | ||
|
||
.party-popper:hover { | ||
transform: scale(1.1); | ||
} | ||
|
||
#confettiCanvas { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100vw; | ||
height: 100vh; | ||
pointer-events: none; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters