-
Notifications
You must be signed in to change notification settings - Fork 0
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
3 changed files
with
125 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,42 @@ | ||
const loveMe = document.querySelector(".loveMe"); | ||
const times = document.querySelector("#times"); | ||
|
||
let clickTime = 0; | ||
let timesClicked = 0; | ||
|
||
loveMe.addEventListener("click", (e) => { | ||
if (clickTime === 0) { | ||
clickTime = new Date().getTime(); | ||
} else { | ||
if (new Date().getTime() - clickTime < 800) { | ||
createHeart(e); | ||
clickTime = 0; | ||
} else { | ||
clickTime = new Date().getTime(); | ||
} | ||
} | ||
}); | ||
|
||
const createHeart = (e) => { | ||
const heart = document.createElement("i"); | ||
heart.classList.add("fas"); | ||
heart.classList.add("fa-heart"); | ||
|
||
const x = e.clientX; | ||
const y = e.clientY; | ||
|
||
const leftOffset = e.target.offsetLeft; | ||
const topOffset = e.target.offsetTop; | ||
|
||
const xInside = x - leftOffset; | ||
const yInside = y - topOffset; | ||
|
||
heart.style.top = `${yInside}px`; | ||
heart.style.left = `${xInside}px`; | ||
|
||
loveMe.appendChild(heart); | ||
|
||
times.innerHTML = ++timesClicked; | ||
|
||
setTimeout(() => heart.remove(), 1000); | ||
}; |
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,30 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" | ||
integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" | ||
crossorigin="anonymous" | ||
referrerpolicy="no-referrer" | ||
/> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Oswald&family=Qahiri&display=swap" | ||
rel="stylesheet" | ||
/> | ||
|
||
<link rel="stylesheet" href="./style.css" /> | ||
<title>Double Heart Click</title> | ||
</head> | ||
<body> | ||
<h3>Dubble click on the image to <i class="fas fa-heart"></i> it</h3> | ||
<small> You liked it <span id="times">0</span> times</small> | ||
|
||
<div class="loveMe"></div> | ||
|
||
<script src="./app.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,53 @@ | ||
*::after, | ||
*::before { | ||
box-sizing: border-box; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
body { | ||
font-family: "Oswald", sans-serif; | ||
text-align: center; | ||
overflow: hidden; | ||
margin: 0; | ||
} | ||
|
||
h3 { | ||
margin-bottom: 0; | ||
align-items: center; | ||
} | ||
|
||
small { | ||
display: block; | ||
margin-bottom: 20px; | ||
text-align: center; | ||
} | ||
|
||
.fa-heart { | ||
color: red; | ||
} | ||
|
||
.loveMe { | ||
height: 440px; | ||
width: 300px; | ||
background: url("https://images.unsplash.com/photo-1504215680853-026ed2a45def?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9=&auto=format&fit=crop&w=334&q=80") | ||
no-repeat center center/cover; | ||
margin: auto; | ||
cursor: pointer; | ||
max-width: 100%; | ||
position: relative; | ||
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22); | ||
} | ||
|
||
.loveMe .fa-heart { | ||
position: absolute; | ||
animation: grow 0.6s linear; | ||
transform: translate(-50%, -50%) scale(0); | ||
} | ||
|
||
@keyframes grow { | ||
to { | ||
transform: translate(-50%, -50%) scale(10); | ||
opacity: 0; | ||
} | ||
} |