Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-08-09 10:22:44 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-08-09 10:22:44 -0700
commit90fe01caaf5b8e0488aef15eb5c76f1e87145797 (patch)
tree8d4bdc49898ed8a3842468b93638400496891b6e /src/modules/pan-zoom.js
parentca9ad3ac2a8a0b5709ae7f55dcff3a7473bb9203 (diff)
Extract programmatic pan coord calculations into gameboard module
Diffstat (limited to 'src/modules/pan-zoom.js')
-rw-r--r--src/modules/pan-zoom.js20
1 files changed, 5 insertions, 15 deletions
diff --git a/src/modules/pan-zoom.js b/src/modules/pan-zoom.js
index 5e224e8..76c77f6 100644
--- a/src/modules/pan-zoom.js
+++ b/src/modules/pan-zoom.js
@@ -1,27 +1,17 @@
import { pan, zoom } from 'pan-zoom';
-const storageKey = 'pan-zoom',
- zoomFactor = 0.25;
+const storageKey = 'pan-zoom';
+const zoomFactor = 0.25;
function restorePanZoomVal(el) {
const storedPanZoomVal = localStorage.getItem(storageKey);
- if (storedPanZoomVal) {
- el.style.transform = storedPanZoomVal;
- }
+ if (storedPanZoomVal) el.style.transform = storedPanZoomVal;
}
function addEventListeners(svg, el) {
- svg.addEventListener('wheel', e => zoom(el, e, zoomFactor), { passive: false });
- svg.addEventListener('pointerdown', e => {
- if (e.button === 0) {
- e.target.setPointerCapture(e.pointerId);
- pan(svg, el, e), { passive: false };
- }
- });
- svg.addEventListener('pointermove', e => {
- console.log('clientX,clientY', `${e.clientX},${e.clientY}`);
- });
+ svg.addEventListener('wheel', zoom(el, zoomFactor), { passive: false });
+ svg.addEventListener('pointerdown', pan(el), { passive: false });
}
function storePanZoomVal(transformMatrix) {