Skip to content

Commit bb80426

Browse files
committed
created project
0 parents commit bb80426

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

index.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<link rel="stylesheet" href="style.css">
9+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css"
10+
integrity="sha512-1PKOgIY59xJ8Co8+NE6FZ+LOAZKjy+KY8iq0G4B3CyeY6wYHN3yt9PW0XpSriVlkMXe40PTKnXrLnZ9+fkDaog=="
11+
crossorigin="anonymous" />
12+
<title>Double Click Heart</title>
13+
</head>
14+
15+
<body>
16+
<h3>Double click on the image to <i class="fas fa-heart"></i>it</h3>
17+
<small>You liked it <span id="times">0</span> times</small>
18+
19+
<div class="loveMe"></div>
20+
21+
22+
<script src="script.js"></script>
23+
</body>
24+
25+
</html>

script.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const loveMe = document.querySelector('.loveMe')
2+
const times = document.querySelector('#times')
3+
4+
let clickTime = 0
5+
let timesClicked = 0
6+
7+
loveMe.addEventListener('click', (e) => {
8+
if(clickTime === 0) {
9+
clickTime = new Date().getTime()
10+
} else {
11+
if((new Date().getTime() - clickTime) < 800) {
12+
createHeart(e)
13+
clickTime = 0
14+
} else {
15+
clickTime = new Date().getTime()
16+
}
17+
}
18+
})
19+
20+
const createHeart = (e) => {
21+
const heart = document.createElement('i')
22+
heart.classList.add('fas')
23+
heart.classList.add('fa-heart')
24+
25+
const x = e.clientX
26+
const y = e.clientY
27+
28+
const leftOffset = e.target.offsetLeft
29+
const topOffset = e.target.offsetTop
30+
31+
const xInside = x - leftOffset
32+
const yInside = y - topOffset
33+
34+
heart.style.top = `${yInside}px`
35+
heart.style.left = `${xInside}px`
36+
37+
loveMe.appendChild(heart)
38+
39+
times.innerHTML = ++timesClicked
40+
41+
setTimeout(() => heart.remove(), 5000)
42+
}

style.css

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
@import url("https://fonts.gooogleapis.com/css?family=Oswald");
2+
3+
* {
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
font-family: "Oswald", sans-serif;
9+
text-align: center;
10+
overflow: hidden;
11+
margin: 0;
12+
}
13+
14+
h3 {
15+
margin-bottom: 0;
16+
text-align: center;
17+
}
18+
19+
small {
20+
display: block;
21+
margin-bottom: 20px;
22+
text-align: center;
23+
}
24+
25+
.fa-heart {
26+
color: red;
27+
}
28+
29+
.loveMe {
30+
height: 440px;
31+
width: 300px;
32+
background: url('https://www.whatsappimages.in/wp-content/uploads/2021/01/Boys-Feeling-Very-Sad-Images-Pics-Downlaod.jpg') no-repeat center center/cover;
33+
margin: auto;
34+
cursor: pointer;
35+
max-width: 100%;
36+
position: relative;
37+
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25),
38+
0 10px 10px rgba(0, 0, 0, 0.22);
39+
}
40+
41+
.loveMe .fa-heart {
42+
position: absolute;
43+
animation: grow 0.6s linear;
44+
transform: translate(-50% , -50%) scale(0);
45+
}
46+
47+
@keyframes grow {
48+
to {
49+
transform: translate(-50% , -50%) scale(10);
50+
opacity: 0;
51+
}
52+
}

0 commit comments

Comments
 (0)