File tree Expand file tree Collapse file tree 3 files changed +79
-0
lines changed Expand file tree Collapse file tree 3 files changed +79
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < title > Like Button Animation</ title >
7
+ < link rel ="stylesheet " href ="style.css ">
8
+ </ head >
9
+ < body >
10
+ < div class ="container ">
11
+ < button class ="like-button " id ="like-button ">
12
+ < span class ="heart " id ="heart "> ❤️</ span > Like
13
+ </ button >
14
+ < p id ="like-count "> 0 Likes</ p >
15
+ </ div >
16
+ < script src ="main.js "> </ script >
17
+ </ body >
18
+ </ html >
Original file line number Diff line number Diff line change
1
+ const likeButton = document . getElementById ( "like-button" ) ;
2
+ const heart = document . getElementById ( "heart" ) ;
3
+ const likeCount = document . getElementById ( "like-count" ) ;
4
+
5
+ let count = 0 ;
6
+
7
+ likeButton . addEventListener ( "click" , ( ) => {
8
+ count ++ ;
9
+ likeCount . textContent = `${ count } Likes` ;
10
+
11
+ // Add 'active' class to trigger animation
12
+ likeButton . classList . toggle ( "active" ) ;
13
+
14
+ // Remove class after animation ends
15
+ setTimeout ( ( ) => {
16
+ likeButton . classList . toggle ( "active" ) ;
17
+ } , 300 ) ; // Match the duration in CSS for animation
18
+ } ) ;
Original file line number Diff line number Diff line change
1
+ body {
2
+ font-family : Arial, sans-serif;
3
+ background-color : # f0f0f0 ;
4
+ display : flex;
5
+ justify-content : center;
6
+ align-items : center;
7
+ height : 100vh ;
8
+ margin : 0 ;
9
+ }
10
+
11
+ .container {
12
+ text-align : center;
13
+ }
14
+
15
+ .like-button {
16
+ background-color : # 007bff ;
17
+ color : white;
18
+ border : none;
19
+ border-radius : 5px ;
20
+ padding : 10px 20px ;
21
+ font-size : 16px ;
22
+ cursor : pointer;
23
+ transition : background-color 0.3s ease;
24
+ position : relative;
25
+ }
26
+
27
+ .like-button : hover {
28
+ background-color : # 0056b3 ;
29
+ }
30
+
31
+ .heart {
32
+ display : inline-block;
33
+ font-size : 24px ;
34
+ transition : transform 0.2s ease;
35
+ }
36
+
37
+ .like-button .active .heart {
38
+ transform : scale (1.5 );
39
+ }
40
+
41
+ .like-button .active {
42
+ background-color : # f32a6d ;
43
+ }
You can’t perform that action at this time.
0 commit comments