Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Celebration Button #1349

Merged
merged 1 commit into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Components/Buttons/Celebration-Button/index.html
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>
71 changes: 71 additions & 0 deletions Components/Buttons/Celebration-Button/script.js
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);
});

40 changes: 40 additions & 0 deletions Components/Buttons/Celebration-Button/style.css
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;
}

13 changes: 13 additions & 0 deletions assets/html_files/buttons.html
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,19 @@ <h1>Wiggle Button</h1>
</a>
</div>
</div>
<div class="box">
<h1>Celebration Button</h1>
<div class="preview">
<a href="../../Components/Buttons/Celebration-Button/index.html" title="Live Preview" target="_blank">
<img src="../images/link.png">
</a>
</div>
<div class="source">
<a href="https://github.com/Rakesh9100/Beautiify/tree/main/Components/Buttons/Celebration-Button" title="Source Code" target="_blank">
<img src="../images/github.png">
</a>
</div>
</div>
</div>
</section>

Expand Down