From 47cac036c66c2bdc002d908457edc9b286d1454a Mon Sep 17 00:00:00 2001 From: Trevor Sayre Date: Wed, 6 Apr 2022 16:42:48 -0400 Subject: [PATCH] Add smooth pixel zooming --- web/_js/main.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/web/_js/main.js b/web/_js/main.js index ba1e60bb..2420e4db 100644 --- a/web/_js/main.js +++ b/web/_js/main.js @@ -271,14 +271,23 @@ async function init(){ initialPinchZoom = zoom; lastPosition = [x, y]; - - if(e.deltaY > 0){ - zoom = zoom / 2; - - } else if(e.deltaY < 0){ - - zoom = zoom * 2; + // Check if we are zooming by pixels + // https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaMode + if (e.deltaMode === 0) { + // Scale the pixel delta by the current zoom factor + // We want to zoom faster when closer, and slower when further + // This creates a smoother experience + zoom -= e.deltaY * (0.001 * zoom); + } else { + if(e.deltaY > 0){ + + zoom = zoom / 2; + + } else if(e.deltaY < 0){ + + zoom = zoom * 2; + } } zoom = Math.max(minZoom, Math.min(maxZoom, zoom));