Double click for heart
A simple double click heart animation using html css and javascript.
<!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" />
<title>Double Click For Heart</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css" />
</head>
<body>
<div class="container">
<i class="fa-solid fa-heart heart"></i>
</div>
</body>
</html>
Now make a css file and link .
/* Import Google font - Poppins */
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600;700&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
body {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #f6f7fb;
}
.container {
position: relative;
height: 420px;
width: 320px;
background-image: url("flower.jpg");
background-size: cover;
background-position: center;
border-radius: 12px;
box-shadow: 0 15px 25px rgba(0, 0, 0, 0.1);
}
.heart {
position: absolute;
color: red;
font-size: 40px;
opacity: 0;
transform: translate(-50%, -50%);
}
.heart.active {
animation: animate 0.8s linear forwards;
}
@keyframes animate {
30% {
font-size: 80px;
opacity: 1;
}
50% {
opacity: 1;
font-size: 60px;
}
70% {
font-size: 70px;
}
80% {
font-size: 60px;
opacity: 1;
}
90% {
font-size: 60px;
opacity: 1;
}
}
now make a js file.
const container = document.querySelector(".container"),
heart = document.querySelector(".heart");
container.addEventListener("dblclick", (e) => {
let xValue = e.clientX - e.target.offsetLeft,
yValue = e.clientY - e.target.offsetTop;
heart.style.left = `${xValue}px`;
heart.style.top = `${yValue}px`;
heart.classList.add("active");
setTimeout(() => {
heart.classList.remove("active");
}, 1000);
});
Superb
ReplyDelete