From c5b02e6a31888b5b7ce95c512c382670ddd6e222 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Fri, 14 Feb 2025 20:01:27 -0500 Subject: [PATCH] [+] Hearts --- src/App.svelte | 22 ++++++++++++++++++---- src/app.sass | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 356a858..2d856f5 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -16,6 +16,7 @@ let state = 0 // Reference to the image element + let mainEl: HTMLElement let divEl: HTMLDivElement let imgEl: HTMLImageElement @@ -92,11 +93,23 @@ imgEl.style.cssText = Object.keys(obj).map(key => `${key}: ${obj[key]}`).join('; ') } - onMount(() => setTimeout(divStyles, 100) -) + onMount(() => setTimeout(divStyles, 100)) + + // This function creates a heart at the click position. + function createHeart(event: MouseEvent) { + console.log("Creating heart") + const heart = document.createElement('div'); + heart.className = 'heart'; + // Position the heart at the cursor's location. + heart.style.left = `${event.clientX + Math.random() * 20 - 10}px`; + heart.style.top = `${event.clientY + Math.random() * 20 - 10}px`; + mainEl.appendChild(heart); + // Remove the heart element after the animation duration (e.g., 2s) + setTimeout(() => heart.remove(), 2000); + } -
+

半熟迷子工作室

@@ -106,7 +119,8 @@
- rana + rana
diff --git a/src/app.sass b/src/app.sass index 9b17b0b..3020bf1 100644 --- a/src/app.sass +++ b/src/app.sass @@ -11,6 +11,7 @@ html width: 100% height: 100% + user-select: none body margin: 0 @@ -26,3 +27,38 @@ a * cursor: url("./matcha_cursor.png") 16 16, auto + +.heart + position: fixed + width: 20px + height: 20px + background: red + transform: rotate(-45deg) + animation: float 2s ease-out forwards + pointer-events: none /* so it doesn’t block further clicks */ + +/* Create the two circular parts of the heart using pseudo-elements */ +.heart::before, .heart::after + content: "" + position: absolute + background: red + border-radius: 50% + width: 20px + height: 20px + +.heart::before + top: -10px + left: 0 + +.heart::after + left: 10px + top: 0 + +@keyframes float + 0% + opacity: 1 + transform: translateY(0) scale(1) rotate(-45deg) + + 100% + opacity: 0 + transform: translateY(-100px) scale(1.5) rotate(-45deg)