Skip to content

Commit

Permalink
Merge pull request #733 from doctor-rutvik14/feature-like-animation
Browse files Browse the repository at this point in the history
Added a new feature: Like button with animation and dynamic counter.
  • Loading branch information
Ayushparikh-code authored Oct 29, 2024
2 parents 7cf6d2b + 771a799 commit b353bdd
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
18 changes: 18 additions & 0 deletions like-button-animation/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Like Button Animation</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<button class="like-button" id="like-button">
<span class="heart" id="heart">❤️</span> Like
</button>
<p id="like-count">0 Likes</p>
</div>
<script src="main.js"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions like-button-animation/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const likeButton = document.getElementById("like-button");
const heart = document.getElementById("heart");
const likeCount = document.getElementById("like-count");

let count = 0;

likeButton.addEventListener("click", () => {
count++;
likeCount.textContent = `${count} Likes`;

// Add 'active' class to trigger animation
likeButton.classList.toggle("active");

// Remove class after animation ends
setTimeout(() => {
likeButton.classList.toggle("active");
}, 300); // Match the duration in CSS for animation
});
43 changes: 43 additions & 0 deletions like-button-animation/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

.container {
text-align: center;
}

.like-button {
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
position: relative;
}

.like-button:hover {
background-color: #0056b3;
}

.heart {
display: inline-block;
font-size: 24px;
transition: transform 0.2s ease;
}

.like-button.active .heart {
transform: scale(1.5);
}

.like-button.active {
background-color: #f32a6d;
}

0 comments on commit b353bdd

Please sign in to comment.