panzoom is a standalone, extensible JavaScript library designed to add intuitive pan and zoom functionalities to both regular DOM elements and SVG graphics. Currently stable at version 9.4.4, the project is actively maintained, with incremental updates focusing on stability and feature enhancements. It offers a highly configurable API, allowing developers to customize interaction behaviors, such as filtering mouse wheel or mouse down events to prevent conflicts with page scrolling or other interactions. A key differentiator is its framework-agnostic design, directly manipulating the target element without imposing dependencies on specific UI frameworks, making it exceptionally versatile for embedding into any web application. It provides a comprehensive event system for tracking pan, zoom, and general transform changes, and importantly, includes a `dispose()` method to ensure proper cleanup of event listeners and prevent memory leaks, which is crucial for dynamic applications. The library ships with TypeScript types, enhancing developer experience in type-safe environments.
npm install panzoomVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to apply pan and zoom functionality to a simple HTML element, including basic configuration options and event filtering for mouse wheel.
Store the panzoom instance returned by `panzoom(element)` and call `instance.dispose()` when the element or component is no longer needed.
Use the `beforeKeyDown` option to filter or disable keyboard events: `panzoom(element, { beforeKeyDown: (e) => !e.metaKey });`Configure panzoom with `beforeWheel: function(e) { return !e.altKey; }` to only allow zoom when the Alt key is pressed.Be aware of the limitation; if touch panning also needs filtering, it must be handled separately or within a custom input plugin.
Ensure you are using `import panzoom from 'panzoom';` for ESM, `const panzoom = require('panzoom');` for CommonJS, or that the CDN script loaded successfully and `window.panzoom` is available.Verify that `document.querySelector` or `document.getElementById` returns the intended element. Check any custom `beforeMouseDown` or `beforeWheel` functions to ensure they are not inadvertently returning `true` (to ignore the event) when interaction is desired.
Whenever an element managed by panzoom is removed from the DOM, or a component using panzoom is unmounted, call `instance.dispose()` on the associated panzoom instance to release resources.
No dependency data recorded yet.