Zoom and pan the canvas

Set wheel speed, zoom limits, and drag-to-pan gestures

Drag canvas · Zoom canvas

Configuration

Enable zoom-canvas for wheel zoom and drag-canvas to pan by dragging empty space. Omitting behaviors enables both.

Set wheel speed with sensitivity and its limits with minZoom and maxZoom. Set ignoreModifierKeys to true to reserve modified drags for brush or lasso selection.

Example

Use the wheel over the canvas and watch the current zoom in the bottom-left corner. Drag empty space with the left mouse button to pan.

Loading example…
Scroll to zoom or drag empty space to pan.
const behaviors = [
  { type: 'zoom-canvas', sensitivity: 1.4, minZoom: 0.4, maxZoom: 2 },
  { type: 'drag-canvas', ignoreModifierKeys: true },
] satisfies [BuiltInBehaviorConfig, BuiltInBehaviorConfig];

Wheel zoom stays between 0.4× and 2×. Calls to zoomTo() and fitView() use their own options. Navigation and dragging options