A simple scroll to zoom handler
import { PanHandler } from 'pan-handler/PanHandler.js'; import { ScrollZoom } from 'pan-handler/plugins/ScrollZoom.js'; const ctx = document.getElementById('myCanvas').getContext('2d'); const panHandler = new PanHandler(ctx, PAN_OPTIONS); const clearAndDraw = () => { panHandler.clear(); // Your draw logic here... }; const scrollZoom = new ScrollZoom((scaleDiff) => { panHandler.incrementZoom(scaleDiff); clearAndDraw(); }); scrollZoom.addTarget(ctx.canvas);
Attach wheel handlers to an element. When that element is mousewheeled the OnZoom callback will fire
You may call addTarget multiple times with different elements to attach handlers to multiple elements.
addTarget
Generated using TypeDoc
A simple scroll to zoom handler
import { PanHandler } from 'pan-handler/PanHandler.js'; import { ScrollZoom } from 'pan-handler/plugins/ScrollZoom.js'; const ctx = document.getElementById('myCanvas').getContext('2d'); const panHandler = new PanHandler(ctx, PAN_OPTIONS); const clearAndDraw = () => { panHandler.clear(); // Your draw logic here... }; const scrollZoom = new ScrollZoom((scaleDiff) => { panHandler.incrementZoom(scaleDiff); clearAndDraw(); }); scrollZoom.addTarget(ctx.canvas);