
Research
/Security News
Contagious Interview Campaign Escalates With 67 Malicious npm Packages and New Malware Loader
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
svg-pan-zoom-container
Advanced tools
A vanilla-js module for adding zoom-on-wheel and pan-on-drag behavior to inline SVG elements.
A vanilla-js module for adding zoom-on-wheel and pan-on-drag behavior to inline SVG elements.
No need to write scripts. Just markup.
data-zoom-on-wheel
attribute to add zoom-on-wheel behavior.data-pan-on-drag
attribute to add pan-on-drag behavior.height
is not "auto"
. The container's height
must not be calculated from its content.That's it!
<script src="https://cdn.jsdelivr.net/npm/svg-pan-zoom-container@0.6.1"></script>
<div
data-zoom-on-wheel
data-pan-on-drag
style="height: 80vh;"
>
<svg viewBox="0 0 100 100">
<circle cx="50" cy="50" r="50" />
</svg>
</div>
$ npm i svg-pan-zoom-container
import 'svg-pan-zoom-container'
<script src="https://cdn.jsdelivr.net/npm/svg-pan-zoom-container@0.6.1"></script>
Some options can be specified as data-zoom-on-wheel
and data-pan-on-drag
attribute value.
Option name and value should be separated by colon (:).
Multiple options should be separated by semicolon (;).
<div
data-zoom-on-wheel="zoom-amount: 0.01; min-scale: 0.3; max-scale: 20;"
data-pan-on-drag="button: right;"
style="height: 80vh;"
>
<svg viewBox="0 0 100 100">
<circle cx="50" cy="50" r="50" />
</svg>
</div>
data-zoom-on-wheel
Name | Type | Default | Description |
---|---|---|---|
zoom-amount | number | 0.002 | Zoom amount per deltaY of wheel events. |
min-scale | number | 1 | Minimum scale. |
max-scale | number | 10 | Maximum scale. |
data-pan-on-drag
Name | Type | Default | Description |
---|---|---|---|
button | "left" | "right" | "left" | Mouse button to drag to pan. |
modifier | "" | "Alt" | "Control" | "Meta" | "Shift" | "" | Drag to pan only when this modifier key is pressed. |
Observe the transform
attribute of the SVG element using MutationObserver
.
const container = document.getElementById('my-svg-container')
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
console.log('scale:', getScale(container));
});
});
observer.observe(container.firstElementChild, {
attributes: true,
attributeFilter: ['transform'],
});
This module provides some functions for scripting to control pan and zoom behavior.
import { pan, zoom, getScale, setScale, resetScale } from 'svg-pan-zoom-container';
<script src="https://cdn.jsdelivr.net/npm/svg-pan-zoom-container@0.6.1"></script>
<script>
const { pan, zoom, getScale, setScale, resetScale } = svgPanZoomContainer;
</script>
Pans.
Returns current scale.
The return value is a 1-based fraction, not a percentage.
Sets scale.
The value
is considered as 1-based fraction, not as percentage.
The options
can be specified as part of the following object (following values are the default):
const options = {
origin: {
clientX: 0,
clientY: 0,
},
minScale: 1,
maxScale: 10,
};
Resets scale and scroll position.
Equivalents to setScale(container, getScale(container) * ratio, options)
.
FAQs
A vanilla-js module for adding zoom-on-wheel and pan-on-drag behavior to inline SVG elements.
The npm package svg-pan-zoom-container receives a total of 746 weekly downloads. As such, svg-pan-zoom-container popularity was classified as not popular.
We found that svg-pan-zoom-container demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.