From b6c550d957bdff542dac2b0c95ac9c5cf0878099 Mon Sep 17 00:00:00 2001 From: ZuxDev Date: Thu, 17 Oct 2024 16:07:30 -0400 Subject: [PATCH] fix scroll jank --- static/map.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/static/map.js b/static/map.js index 47fd860..a615e3d 100644 --- a/static/map.js +++ b/static/map.js @@ -21,6 +21,7 @@ let center = [0, 0]; let lastPos = [0, 0]; let isMouse = false; let zoom = 1; +let timer = 0; let id = ''; @@ -69,16 +70,26 @@ function mouseDown(e) { } function wheel(e) { + document.body.style.overflow = 'hidden'; + + if (timer != 0) clearTimeout(timer); + + timer = setTimeout(function() { + document.body.style.overflow = ''; + },400) + mpos[0] -= lastPos[0]; mpos[1] -= lastPos[1]; - mpos[0] *= (1.005 ** -e.deltaY) - mpos[1] *= (1.005 ** -e.deltaY) + let f = (2 ** -(e.deltaY/256)); + + mpos[0] *= f; + mpos[1] *= f; mpos[0] += lastPos[0]; mpos[1] += lastPos[1]; - zoom *= (1.005 ** -e.deltaY) + zoom *= f; } function move() {