dom-pan-zoom 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +144 -0
- package/dist/dom-pan-zoom.umd.js +777 -0
- package/dist/dom-pan-zoom.umd.js.map +1 -0
- package/dist/dom-pan-zoom.umd.min.js +1 -0
- package/dist/index.cjs +771 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +769 -0
- package/dist/index.js.map +1 -0
- package/package.json +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Stephan Wagner
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# domPanZoom
|
|
2
|
+
|
|
3
|
+
A lightweight library providing mobile friendly panning and zooming to any HTML DOM element.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
### npm
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install dom-pan-zoom --save
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import domPanZoom from 'dom-pan-zoom';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### CDN
|
|
20
|
+
|
|
21
|
+
```html
|
|
22
|
+
<script src="https://cdn.jsdelivr.net/npm/dom-pan-zoom@latest/dist/dom-pan-zoom.umd.min.js"></script>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
You need two HTML DOM elements.\
|
|
30
|
+
The panZoom element within a wrapper element:
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<div id="my-wrapper">
|
|
34
|
+
<div id="my-container">
|
|
35
|
+
<p>You can add any HTML here<p>
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Then create a new instance of domPanZoom:
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
new domPanZoom({
|
|
44
|
+
wrapperElement: '#my-wrapper',
|
|
45
|
+
panZoomElement: '#my-container'
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The options `wrapperElement` and `panZoomElement` are required.\
|
|
50
|
+
You can use any query selector or the actual DOM element instance.
|
|
51
|
+
|
|
52
|
+
> It is highly recommended to give the `panZoomElement` an actual width and height via CSS to avoid size calculation errors due to DOM drawing issues.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Options
|
|
57
|
+
|
|
58
|
+
You can pass the following options into domPanZoom:
|
|
59
|
+
|
|
60
|
+
| Option | Default | |
|
|
61
|
+
| --- | --- | --- |
|
|
62
|
+
| `center` | `true` | Start with a centered position. This option overrides `initalPanX` and `initialPanY` |
|
|
63
|
+
| `bounds` | `cover` | Set this option to `'contain'` or `'cover'` to limit the boundries of the panZoomElement to the wrapperElement. This works similar to the CSS property background-size: contain / cover. Setting this option might effect the option minZoom |
|
|
64
|
+
| `minZoom` | `0.1` | Minimum zoom, `0.5` would be half the original size |
|
|
65
|
+
| `maxZoom` | `10` | Maximum zoom, `2` would be double the original size |
|
|
66
|
+
| `panStep` | `10` | How many percent to pan by default with the panning methods panLeft, panRight, panUp and panDown |
|
|
67
|
+
| `zoomStep` | `50` | How many percent to zoom by default with the methods zoomIn and zoomOut |
|
|
68
|
+
| `zoomWheelSpeed` | `1` | The speed in which to zoom when using the mouse wheel |
|
|
69
|
+
| `initialZoom` | `1` | Initial zoom level |
|
|
70
|
+
| `initialPanX` | `0` | Initial horizontal pan in percent |
|
|
71
|
+
| `initialPanY` | `0` | Initial vertical pan in percent |
|
|
72
|
+
| `transitionSpeed` | `400` | Transition speed in milliseconds, higher values are slower |
|
|
73
|
+
|
|
74
|
+
### E.g.
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
new domPanZoom({
|
|
78
|
+
wrapperElement: '#my-wrapper',
|
|
79
|
+
panZoomElement: '#my-container',
|
|
80
|
+
bounds: false,
|
|
81
|
+
minZoom: 1
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Methods
|
|
88
|
+
|
|
89
|
+
You can use the following methods:
|
|
90
|
+
|
|
91
|
+
| Getters | |
|
|
92
|
+
| --- | --- |
|
|
93
|
+
| `.getPan()` | Returns an object with X and Y values of current pan position. You can pass `true` to get the actual pixel values, e.g. `.getPan(true)` |
|
|
94
|
+
| `.getPanX()` | Returns the current horizontal position. You can pass `true` to get the actual pixel values, e.g. `.getPanX(true)` |
|
|
95
|
+
| `.getPanY()` | Returns the current vertical position. You can pass `true` to get the actual pixel values, e.g. `.getPanY(true)` |
|
|
96
|
+
| `.getZoom()` | Returns the current zoom level |
|
|
97
|
+
|
|
98
|
+
| Setters | |
|
|
99
|
+
| --- | --- |
|
|
100
|
+
| `.panLeft()`<br>`.panRight()`<br>`.panUp()`<br>`.panDown()` | Pan a specific direction. You can pass a number to pan a specific amount (in percent). Pass `true` as first or second argument to pan instantly, e.g. `.panLeft(50)`, `.panRight(true)`, `.panUp(30, true)` |
|
|
101
|
+
| `.panTo(x, y)` | Pan to a specific position. The `x` and `y` values are in percent, so `.panTo(50, 50)` will pan to the center. Pass `true` as third argument to pan instantly, e.g. `.panTo(50, 50, true)`
|
|
102
|
+
| `.center()` | Pan to centered position. Pass `true` to center instantly, e.g. `.center(true)` |
|
|
103
|
+
| `.zoomIn()`<br>`.zoomOut()` | Zoom in and out. You can pass a number to zoom a specific amount (in percent). Pass `true` as first or second argument to zoom instantly, e.g. `.zoomIn(20)`, `.zoomIn(true)`, `.zoomIn(50, true)` |
|
|
104
|
+
| `.zoomTo(2)` | Zoom to a specific zoom level. Pass `true` as a second argument to zoom instantly, e.g. `.zoomTo(2, true)` |
|
|
105
|
+
|
|
106
|
+
### E.g.
|
|
107
|
+
|
|
108
|
+
```javascript
|
|
109
|
+
var myDomPanZoom = new domPanZoom({
|
|
110
|
+
wrapperElement: '#my-wrapper',
|
|
111
|
+
panZoomElement: '#my-container'
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
myDomPanZoom.panTo(20, 80);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Events
|
|
120
|
+
|
|
121
|
+
| Event | |
|
|
122
|
+
| --- | --- |
|
|
123
|
+
| `onInit` | Triggered once domPanZoom is initialized |
|
|
124
|
+
| `onChange` | Triggered when panning or zooming |
|
|
125
|
+
| `onZoom` | Triggered when zooming |
|
|
126
|
+
| `onPan` | Triggered when panning |
|
|
127
|
+
|
|
128
|
+
### E.g.
|
|
129
|
+
|
|
130
|
+
```javascript
|
|
131
|
+
new domPanZoom({
|
|
132
|
+
wrapperElement: '#my-wrapper',
|
|
133
|
+
panZoomElement: '#my-container'
|
|
134
|
+
onZoom: function (position) {
|
|
135
|
+
console.log(this.zoom, position);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Attribution
|
|
143
|
+
|
|
144
|
+
This library is heavily inspired by https://github.com/anvaka/panzoom.
|