From 4016ed0d53d8903c9c57ce9a0922c1843cb3ed49 Mon Sep 17 00:00:00 2001 From: Julian Freeman Date: Sun, 22 Mar 2026 17:03:57 -0400 Subject: [PATCH] fix scale point --- src/App.vue | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/App.vue b/src/App.vue index 244161b..4561934 100644 --- a/src/App.vue +++ b/src/App.vue @@ -181,8 +181,32 @@ const handleTimelineClick = (e: MouseEvent) => { const handleTimelineWheel = (e: WheelEvent) => { if (e.ctrlKey) { e.preventDefault(); + if (!timelineRef.value) return; + + const rect = timelineRef.value.getBoundingClientRect(); + const mouseYInViewport = e.clientY - rect.top; + const scrollOffset = timelineRef.value.scrollTop; + + // Position of cursor relative to the content total height before zoom + const cursorYInContent = mouseYInViewport + scrollOffset; + const oldRulerHeight = rulerHeight.value; + + // Perform zoom change const delta = e.deltaY > 0 ? -0.2 : 0.2; - timelineZoom.value = Math.min(Math.max(0.5, timelineZoom.value + delta), 15); + const newZoom = Math.min(Math.max(0.5, timelineZoom.value + delta), 15); + + if (newZoom === timelineZoom.value) return; + + timelineZoom.value = newZoom; + + // Wait for DOM update or calculate it + const newRulerHeight = TOTAL_MINUTES * newZoom; + + // Calculate new scroll position to keep cursor point fixed + const newScrollTop = (cursorYInContent / oldRulerHeight) * newRulerHeight - mouseYInViewport; + + timelineRef.value.scrollTop = newScrollTop; + updateSettings(); } }; @@ -227,18 +251,6 @@ const handleTimelineWheel = (e: WheelEvent) => { @change="loadTimeline" class="w-full bg-white border border-[#E5E5E7] rounded-xl px-4 py-2 text-sm font-medium focus:ring-2 focus:ring-[#007AFF]/20 focus:border-[#007AFF] outline-none transition-all" /> -
- 缩放 - -
@@ -267,7 +279,7 @@ const handleTimelineWheel = (e: WheelEvent) => {