From bd3bf548c27f6be204cf89d98944b76ccdd01078 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 18 Apr 2024 19:17:05 -0700 Subject: feat(badges): limit rotation --- src/lib/BadgeWall/BadgePreview.svelte | 3 +++ src/lib/FallbackBadge.svelte | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/BadgeWall/BadgePreview.svelte b/src/lib/BadgeWall/BadgePreview.svelte index 689ae927..dd2b7fd9 100644 --- a/src/lib/BadgeWall/BadgePreview.svelte +++ b/src/lib/BadgeWall/BadgePreview.svelte @@ -20,6 +20,7 @@ const handleMouseMove = (event: MouseEvent) => { const boundingRectangle = badgeReference.getBoundingClientRect(); const factor = 1.25; + const limit = 300 * 1.75; if ($mouse.x === 0 && $mouse.y === 0) $mouse = { x: event.clientX, y: event.clientY }; @@ -27,6 +28,8 @@ (-(event.clientX - boundingRectangle.left - boundingRectangle.width / 2) - $mouse.x) * factor; $mouse.y += (-(event.clientY - boundingRectangle.top - boundingRectangle.height / 2) - $mouse.y) * factor; + $mouse.x = Math.max(Math.min($mouse.x, limit), -limit); + $mouse.y = Math.max(Math.min($mouse.y, limit), -limit); }; const handleMouseLeave = () => { diff --git a/src/lib/FallbackBadge.svelte b/src/lib/FallbackBadge.svelte index 8e5c9a5d..f7953e30 100644 --- a/src/lib/FallbackBadge.svelte +++ b/src/lib/FallbackBadge.svelte @@ -22,7 +22,7 @@ const mouse = tweened( { x: 0, y: 0 }, { - duration: 1, + duration: 75, easing: cubicOut } ); @@ -40,6 +40,7 @@ const handleMouseMove = (event: MouseEvent) => { const boundingRectangle = badgeReference.getBoundingClientRect(); const factor = 1.25; + const limit = 50; if ($mouse.x === 0 && $mouse.y === 0) $mouse = { x: event.clientX, y: event.clientY }; @@ -47,6 +48,8 @@ (-(event.clientX - boundingRectangle.left - boundingRectangle.width / 2) - $mouse.x) * factor; $mouse.y += (-(event.clientY - boundingRectangle.top - boundingRectangle.height / 2) - $mouse.y) * factor; + $mouse.x = Math.max(Math.min($mouse.x, limit), -limit); + $mouse.y = Math.max(Math.min($mouse.y, limit), -limit); }; const handleMouseLeave = () => { -- cgit v1.2.3