From 5cb1e01669c66cd9503f0dbb04fd1e404cd3f1d8 Mon Sep 17 00:00:00 2001 From: anuj Date: Wed, 29 Jan 2025 01:46:12 -0800 Subject: [PATCH] heart in center on like --- double-click-heart/index.html | 2 +- double-click-heart/script.js | 59 +++++++++++------------------------ double-click-heart/style.css | 21 ++++++------- 3 files changed, 29 insertions(+), 53 deletions(-) diff --git a/double-click-heart/index.html b/double-click-heart/index.html index 1278213..bb29909 100644 --- a/double-click-heart/index.html +++ b/double-click-heart/index.html @@ -11,7 +11,7 @@

Double click on the image to it

You liked it 0 times -
+
❤️
diff --git a/double-click-heart/script.js b/double-click-heart/script.js index a121037..fbb12bb 100644 --- a/double-click-heart/script.js +++ b/double-click-heart/script.js @@ -1,42 +1,19 @@ -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) -} \ No newline at end of file +var car = document.querySelector('.loveMe'); +var clutter = 0; +var times = document.querySelector('#times'); + +car.addEventListener('dblclick', () => { + clutter++; + var heart = document.querySelector('#heart'); + heart.style.opacity = 1; + heart.style.transform = 'scale(1)'; + setTimeout(() => { + heart.style.transform = 'scale(0)'; + heart.style.opacity = '0'; + }, 600) + setTimeout(()=>{ + heart.style.display = 'initial'; + },620) + times.innerHTML = clutter; +}) \ No newline at end of file diff --git a/double-click-heart/style.css b/double-click-heart/style.css index c578a1e..881acab 100644 --- a/double-click-heart/style.css +++ b/double-click-heart/style.css @@ -34,20 +34,19 @@ small { margin: auto; cursor: pointer; max-width: 100%; + display: flex; + align-items: center; + user-select: none; + justify-content: center; position: relative; box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22); overflow: hidden; } -.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; - } -} +#heart{ + font-size: 15vw; + opacity: 0; + transform: scale(0); + transition: 0.4s; +} \ No newline at end of file