diff --git a/static/js/main.js b/static/js/main.js index d3886ab..cab7295 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -322,13 +322,29 @@ const cvPaper = document.querySelector('.cv-paper'); if (!cvPaper) return; - // Convert percentage to scale factor (100 = 1.0, 150 = 1.5, etc.) - const scaleFactor = zoomValue / 100; + // Get current scale to calculate ratio + const currentTransform = cvPaper.style.transform; + const currentScaleMatch = currentTransform.match(/scale\(([\d.]+)\)/); + const oldScale = currentScaleMatch ? parseFloat(currentScaleMatch[1]) : 1.0; + + // Convert percentage to scale factor (100 = 1.0, 150 = 1.5, etc.) + const newScale = zoomValue / 100; - // Simple transform without scroll manipulation - // CSS transform-origin is set to "top center" so page scales from top requestAnimationFrame(() => { - cvPaper.style.transform = `scale(${scaleFactor})`; + // Store current scroll position + const oldScrollTop = window.pageYOffset || document.documentElement.scrollTop; + + // Apply the new scale + cvPaper.style.transform = `scale(${newScale})`; + + // Calculate proportional scroll position to maintain visual position + // If zooming from 100% to 50%, content at pixel 1000 moves to pixel 500 + // So we need to scroll to pixel 500 to see the same content + const scaleRatio = newScale / oldScale; + const newScrollTop = oldScrollTop * scaleRatio; + + // Apply new scroll position to keep same content visible + window.scrollTo(0, newScrollTop); // Update display updateZoomDisplay(zoomValue);