UNPKG

26.2 kBMarkdownView Raw
1# Panzoom
2
3[![Build Status](https://travis-ci.org/timmywil/panzoom.png?branch=master)](https://travis-ci.org/timmywil/panzoom)
4
5**[Examples](https://timmywil.com/panzoom/demo/)**
6
7---
8
9Panzoom is a small library (~3.7kb gzipped) to add panning and zooming functionality to an element.
10Rather than using absolute positioning or setting width and height, Panzoom uses CSS transforms to take advantage of hardware/GPU acceleration in the browser, which means the element can be _anything_: an image, a video, an iframe, a canvas, text, WHATEVER.
11
12For common support questions, see [the FAQ](https://github.com/timmywil/panzoom#faq).
13
14## Browser support
15
16Here is a list of [currently supported browsers](https://browserl.ist/?q=%3E0.25%25%2C+not+op_mini+all).
17
18## Mobile support
19
20iOS, Android, and Windows Mobile are supported.
21
22Panzoom includes support for touch gestures and even supports **pinch gestures** for zooming. It is perfectly suited for both mobile and desktop browsers. It uses [pointer events](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events) by default wherever supported.
23
24## SVG support
25
26Panzoom supports panning and zooming SVG elements directly.
27
28In IE11, CSS animations/transitions do not work on SVG elements, at least for the transform style. They do work in other browsers.
29
30One could implement transitions manually in IE11 using the `setTransform` option and integrating a tweening library for javascript animations (such as [tween.js](https://www.createjs.com/#!/TweenJS)).
31
32## Installing
33
34With npm:
35
36```bash
37$ npm install --save @panzoom/panzoom
38```
39
40With yarn:
41
42```bash
43$ yarn add @panzoom/panzoom
44```
45
46Panzoom uses [UMD](https://github.com/umdjs/umd) and can be loaded a lot of ways.
47
48With ES6 imports:
49
50```js
51import Panzoom from '@panzoom/panzoom'
52```
53
54With commonjs or browserify:
55
56```js
57const Panzoom = require('@panzoom/panzoom')
58```
59
60With an AMD loader in an anonymous module:
61
62```js
63define(['@panzoom/panzoom'], function (Panzoom) {
64 const elem = document.getElementById('panzoom-element')
65 Panzoom(elem)
66})
67```
68
69With a script tag:
70
71```html
72<script src="/js/panzoom.js"></script>
73```
74
75## Usage
76
77```js
78const elem = document.getElementById('panzoom-element')
79const panzoom = Panzoom(elem, {
80 maxScale: 5
81})
82panzoom.pan(10, 10)
83panzoom.zoom(2, { animate: true })
84
85// Panning and pinch zooming are bound automatically (unless disablePan is true).
86// There are several available methods for zooming
87// that can be bound on button clicks or mousewheel.
88button.addEventListener('click', panzoom.zoomIn)
89elem.parentElement.addEventListener('wheel', panzoom.zoomWithWheel)
90```
91
92## FAQ
93
941\. What is `transform-origin` and why is it added to the panzoom element?
95
96- The `transform-origin` is the origin from which transforms are applied. Panzoom ensures the defaults are set to what it expects to calculate focal point zooming.
97- HTML elements default to '50% 50%'.
98- SVG elements default to '0 0'.
99
1002\. I am using Panzoom with an `<object>` tag and it's not working. What's wrong?
101
102Object elements can eat up events, making it so they never reach Panzoom. To fix this, disable pointer events (`pointer-events: none`) on the `<object>` tag and call Panzoom using a wrapper.
103
1043\. My links aren't working! How do I enable an anchor within a panzoom element?
105
106Add class `options.excludeClass` (default is `"panzoom-exclude"`) to whatever element you want to be clickable. Panzoom will check for this class before handling the event.
107Alternatively, add a reference to the element to the `exclude` option, or call `event.stopImmediatePropagation()` in an event handler on the clickable element.
108
109## A note on the async nature of Panzoom
110
111In some cases, setting one thing and then setting another synchronously will not work as intended.
112
113For instance, the following usually works fine.
114
115```js
116const panzoom = Panzoom(elem)
117panzoom.zoom(2)
118panzoom.pan(100, 100)
119```
120
121However, you might find that the things start breaking when the `contain` option is set.
122
123This is due to the fact that in order for Panzoom to retrieve proper dimensions, the scale needs to be painted.
124
125If you find that things aren't looking quite right, try the following instead...
126
127```js
128panzoom.zoom(2)
129setTimeout(() => panzoom.pan(100, 100))
130```
131
132---
133
134## Documentation
135
136### Panzoom
137
138**Panzoom**(`elem`, `options?`): [PanzoomObject](#PanzoomObject)
139
140#### Parameters
141
142| Name | Type |
143| :--------- | :---------------------------------------------------- |
144| `elem` | `HTMLElement` \| `SVGElement` |
145| `options?` | `Omit`<[PanzoomOptions](#PanzoomOptions), `"force"`\> |
146
147#### Returns
148
149[PanzoomObject](#PanzoomObject)
150
151#### Defined in
152
153[panzoom.ts:58](https://github.com/timmywil/panzoom/blob/22fb0b3/src/panzoom.ts#L58)
154
155## `PanzoomOptions`
156
157Includes `MiscOptions`, `PanOptions`, and `ZoomOptions`
158
159## MiscOptions
160
161These options can be passed to `Panzoom()`, as well as any pan or zoom function. One exception is `force`, which can only be passed to methods like `pan()` or `zoom()`, but not `Panzoom()` or `setOptions()` as it should not be set globally.
162
163### animate
164
165`Optional` **animate**: `boolean` (Default: **false**)
166
167Whether to animate transitions
168
169#### Defined in
170
171[types.ts:21](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L21)
172
173### canvas
174
175`Optional` **canvas**: `boolean` (Default: **false**)
176
177This option treats the Panzoom element's parent
178as a canvas. Effectively, Panzoom binds the
179down handler to the parent instead of the Panzoom
180element, so that pointer events anywhere on the "canvas"
181moves its children. See issue #472.
182
183**Note**: setting this option to `true` also changes
184where the `cursor` style is applied (i.e. the parent).
185
186#### Defined in
187
188[types.ts:32](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L32)
189
190### duration
191
192`Optional` **duration**: `number` (Default: **200**)
193
194Duration of the transition (ms)
195
196#### Defined in
197
198[types.ts:34](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L34)
199
200### easing
201
202`Optional` **easing**: `string` (Default: **"ease-in-out"**)
203
204CSS Easing used for transitions
205
206#### Defined in
207
208[types.ts:36](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L36)
209
210### exclude
211
212`Optional` **exclude**: `Element`[] (Default: **[]**)
213
214Add elements to this array that should be excluded
215from Panzoom handling.
216Ancestors of event targets are also checked.
217e.g. links and buttons that should not propagate the click event.
218
219#### Defined in
220
221[types.ts:43](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L43)
222
223### excludeClass
224
225`Optional` **excludeClass**: `string` (Default: **"panzoom-exclude"**)
226
227Add this class to any element within the Panzoom element
228that you want to exclude from Panzoom handling. That
229element's children will also be excluded.
230e.g. links and buttons that should not propagate the click event.
231
232#### Defined in
233
234[types.ts:50](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L50)
235
236### force
237
238`Optional` **force**: `boolean`
239
240`force` should be used sparingly to temporarily
241override and ignore options such as disablePan,
242disableZoom, and panOnlyWhenZoomed.
243This option cannot be passed to the
244Panzoom constructor or setOptions (to avoid
245setting this option globally).
246
247```js
248// Overrides disablePan and panOnlyWhenZoomed
249panzoom.pan(50, 100, { force: true })
250// Overrides disableZoom
251panzoom.zoom(1, { force: true })
252```
253
254#### Defined in
255
256[types.ts:66](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L66)
257
258### handleStartEvent
259
260`Optional` **handleStartEvent**: (`event`: `Event`) => `void` (Default: **(e: Event) => {
261e.preventDefault()
262e.stopPropagation()
263}**)
264
265On the first pointer event, when panning starts,
266the default Panzoom behavior is to call
267`event.preventDefault()` and `event.stopPropagation()`
268on that event. The former is almost certainly a necessity;
269the latter enables Panzoom elements within Panzoom elements.
270
271But there are some cases where the default is
272not the desired behavior. Set this option to override that behavior.
273
274```js
275// Only call preventDefault()
276Panzoom(elem, {
277 handleStartEvent: (event) => {
278 event.preventDefault()
279 }
280})
281// Do nothing.
282// This can change dragging behavior on mobile.
283Panzoom(elem, {
284 handleStartEvent: () => {}
285})
286```
287
288##### Parameters
289
290| Name | Type |
291| :------ | :------ |
292| `event` | `Event` |
293
294##### Returns
295
296`void`
297
298#### Defined in
299
300[types.ts:91](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L91)
301
302### noBind
303
304`Optional` **noBind**: `boolean`
305
306Skip binding the default Panzoom event listeners
307
308#### Defined in
309
310[types.ts:95](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L95)
311
312### origin
313
314`Optional` **origin**: `string`
315
316**Change this at your own risk.**
317The `transform-origin` is the origin from which transforms are applied.
318Default: `'50% 50%'` for HTML and `'0 0'` for SVG.
319The defaults are set because changing the `transform-origin` on
320SVG elements doesn't work in IE.
321
322Changing this should work with many things, but
323it will break focal point zooming, which assumes the
324defaults are set to do the more complicated calculations.
325
326And again, changing this for SVG in IE doesn't work at all.
327
328#### Defined in
329
330[types.ts:109](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L109)
331
332### overflow
333
334`Optional` **overflow**: `string` (Default: **"hidden"**)
335
336The overflow CSS value for the parent. Defaults to 'hidden'
337
338#### Defined in
339
340[types.ts:111](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L111)
341
342### setTransform
343
344`Optional` **setTransform**: (`elem`: `HTMLElement` \| `SVGElement`, `__namedParameters`: CurrentValues, `_options?`: PanzoomOptions) => `void`
345
346Override the transform setter.
347This is exposed mostly so the user could
348set other parts of a transform
349aside from scale and translate.
350Default is defined in src/css.ts.
351
352```js
353// This example always sets a rotation
354// when setting the scale and translation
355const panzoom = Panzoom(elem, {
356 setTransform: (elem, { scale, x, y }) => {
357 panzoom.setStyle('transform', `rotate(0.5turn) scale(${scale}) translate(${x}px, ${y}px)`)
358 }
359})
360```
361
362Set the transform using the proper prefix
363
364##### Parameters
365
366| Name | Type |
367| :------------------ | :---------------------------- |
368| `elem` | `HTMLElement` \| `SVGElement` |
369| `__namedParameters` | CurrentValues |
370| `_options?` | PanzoomOptions |
371
372##### Returns
373
374`void`
375
376#### Defined in
377
378[types.ts:129](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L129)
379
380### silent
381
382`Optional` **silent**: `boolean`
383
384Silence all events
385
386#### Defined in
387
388[types.ts:131](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L131)
389
390### startScale
391
392`Optional` **startScale**: `number` (Default: **1**)
393
394Scale used to set the beginning transform
395
396#### Defined in
397
398[types.ts:137](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L137)
399
400### startX
401
402`Optional` **startX**: `number` (Default: **0**)
403
404X Value used to set the beginning transform
405
406#### Defined in
407
408[types.ts:133](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L133)
409
410### startY
411
412`Optional` **startY**: `number` (Default: **0**)
413
414Y Value used to set the beginning transform
415
416#### Defined in
417
418[types.ts:135](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L135)
419
420### touchAction
421
422`Optional` **touchAction**: `string` (Default: **"none"**)
423
424This value is used to set touch-action on both the
425Panzoom element and its parent.
426It is needed because that the native scroll on mobile
427interferes with panning and pinch zooming.
428Set this to empty string to re-enable scrolling
429on mobile, but note that both scrolling and panning
430cannot work at the same time.
431
432#### Defined in
433
434[types.ts:147](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L147)
435
436## PanOptions (includes MiscOptions)
437
438### contain
439
440`Optional` **contain**: `"inside"` \| `"outside"`
441
442Contain the panzoom element either
443inside or outside the parent.
444Inside: The panzoom element is smaller
445than its parent and cannot be panned
446to the outside.
447Outside: The panzoom element is larger
448than its parent and cannot be panned
449to the inside. In other words, no
450empty space around the element will be shown.
451
452**Note**: the containment pan adjustment is not affected by the `disablePan` option.
453
454#### Defined in
455
456[types.ts:166](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L166)
457
458### cursor
459
460`Optional` **cursor**: `string` (Default: **"move"**)
461
462The cursor style to set on the panzoom element
463
464#### Defined in
465
466[types.ts:168](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L168)
467
468### disablePan
469
470`Optional` **disablePan**: `boolean` (Default: **false**)
471
472Disable panning functionality.
473Note: disablePan does not affect focal point zooming or the contain option.
474The element will still pan accordingly.
475
476#### Defined in
477
478[types.ts:174](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L174)
479
480### disableXAxis
481
482`Optional` **disableXAxis**: `boolean` (Default: **false**)
483
484Pan only on the Y axis
485
486#### Defined in
487
488[types.ts:176](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L176)
489
490### disableYAxis
491
492`Optional` **disableYAxis**: `boolean` (Default: **false**)
493
494Pan only on the X axis
495
496#### Defined in
497
498[types.ts:178](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L178)
499
500### panOnlyWhenZoomed
501
502`Optional` **panOnlyWhenZoomed**: `boolean` (Default: **false**)
503
504Disable panning while the scale is equal to the starting value
505
506#### Defined in
507
508[types.ts:182](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L182)
509
510### relative
511
512`Optional` **relative**: `boolean` (Default: **false**)
513
514When passing x and y values to .pan(), treat the values as relative to their current values
515
516#### Defined in
517
518[types.ts:180](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L180)
519
520## ZoomOptions (includes MiscOptions)
521
522### disableZoom
523
524`Optional` **disableZoom**: `boolean` (Default: **false**)
525
526Disable zooming functionality
527
528#### Defined in
529
530[types.ts:187](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L187)
531
532### focal
533
534`Optional` **focal**: `Object`
535
536Zoom to the given point on the panzoom element.
537This point is expected to be relative to
538the panzoom element's dimensions and is unrelated
539to the parent dimensions.
540
541#### Type declaration
542
543| Name | Type |
544| :--- | :------- |
545| `x` | `number` |
546| `y` | `number` |
547
548#### Defined in
549
550[types.ts:194](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L194)
551
552### maxScale
553
554`Optional` **maxScale**: `number` (Default: **4**)
555
556The maximum scale when zooming
557
558#### Defined in
559
560[types.ts:198](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L198)
561
562### minScale
563
564`Optional` **minScale**: `number` (Default: **0.125**)
565
566The minimum scale when zooming
567
568#### Defined in
569
570[types.ts:196](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L196)
571
572### step
573
574`Optional` **step**: `number` (Default: **0.3**)
575
576The step affects zoom calculation when zooming with a mouse wheel, when pinch zooming, or when using zoomIn/zoomOut
577
578#### Defined in
579
580[types.ts:200](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L200)
581
582## PanzoomObject
583
584These methods are available after initializing Panzoom.
585
586### bind
587
588**bind**: () => `void`
589
590Bind the default down, move, and up event listeners to the Panzoom element.
591This does not normally need to be called.
592It gets called by default when creating a new Panzoom object,
593but can be skipped with the `noBind` option.
594
595```js
596const panzoom = Panzoom(elem, { noBind: true })
597// ...
598panzoom.bind()
599```
600
601##### Returns
602
603`void`
604
605#### Defined in
606
607[types.ts:227](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L227)
608
609### destroy
610
611**destroy**: () => `void`
612
613Remove all event listeners bound to the the Panzoom element
614
615##### Returns
616
617`void`
618
619#### Defined in
620
621[types.ts:229](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L229)
622
623### eventNames
624
625**eventNames**: `Object`
626
627This object exposes the event names used by Panzoom,
628depending on the current browser's support for
629Pointer or Touch events.
630
631#### Type declaration
632
633| Name | Type |
634| :----- | :------- |
635| `down` | `string` |
636| `move` | `string` |
637| `up` | `string` |
638
639#### Defined in
640
641[types.ts:235](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L235)
642
643### getOptions
644
645**getOptions**: () => PanzoomOptions
646
647Returns a _copy_ of the current options object
648
649##### Returns
650
651PanzoomOptions
652
653#### Defined in
654
655[types.ts:241](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L241)
656
657### getPan
658
659**getPan**: () => { `x`: `number` ; `y`: `number` }
660
661Get the current x/y translation
662
663##### Returns
664
665`Object`
666
667| Name | Type |
668| :--- | :------- |
669| `x` | `number` |
670| `y` | `number` |
671
672#### Defined in
673
674[types.ts:237](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L237)
675
676### getScale
677
678**getScale**: () => `number`
679
680Get the current scale
681
682##### Returns
683
684`number`
685
686#### Defined in
687
688[types.ts:239](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L239)
689
690### pan
691
692**pan**: (`x`: `string` \| `number`, `y`: `string` \| `number`, `panOptions?`: PanOptions) => [CurrentValues](#CurrentValues)
693
694Pan the Panzoom element to the given x and y coordinates
695
696```js
697// Translates the element to 50px, 100px
698panzoom.pan(50, 100)
699// Pans the element right 10px and down 10px from its current position
700panzoom.pan(10, 10, { relative: true })
701```
702
703##### Parameters
704
705| Name | Type |
706| :------------ | :------------------- |
707| `x` | `string` \| `number` |
708| `y` | `string` \| `number` |
709| `panOptions?` | PanOptions |
710
711##### Returns
712
713[CurrentValues](#CurrentValues)
714
715#### Defined in
716
717[types.ts:252](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L252)
718
719### reset
720
721**reset**: (`resetOptions?`: PanzoomOptions) => [CurrentValues](#CurrentValues)
722
723Reset the pan and zoom to startX, startY, and startScale.
724Animates by default, ignoring the global option.
725Pass `{ animate: false }` to override.
726Reset ignores the `disablePan`, `disableZoom`, and `panOnlyWhenZoomed` options.
727Pass `{ force: false }` to override.
728
729```js
730panzoom.reset()
731panzoom.reset({ animate: false })
732```
733
734##### Parameters
735
736| Name | Type |
737| :-------------- | :------------- |
738| `resetOptions?` | PanzoomOptions |
739
740##### Returns
741
742[CurrentValues](#CurrentValues)
743
744#### Defined in
745
746[types.ts:265](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L265)
747
748### resetStyle
749
750**resetStyle**: () => `void`
751
752Reset the styles set on the Panzoom element
753and its parent (such as overflow, cursor, etc.)
754
755```js
756panzoom.resetStyle()
757```
758
759##### Returns
760
761`void`
762
763#### Defined in
764
765[types.ts:274](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L274)
766
767### setOptions
768
769**setOptions**: (`options?`: PanzoomOptions) => `void`
770
771Change any number of options on a Panzoom instance.
772Setting some options will have side-effects.
773For instance, changing the cursor option
774will also set the cursor style.
775
776```js
777const panzoom = Panzoom(elem, { cursor: 'move' })
778// ...
779panzoom.setOptions({ cursor: 'default' })
780```
781
782##### Parameters
783
784| Name | Type |
785| :--------- | :------------- |
786| `options?` | PanzoomOptions |
787
788##### Returns
789
790`void`
791
792#### Defined in
793
794[types.ts:287](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L287)
795
796### setStyle
797
798**setStyle**: (`name`: `string`, `value`: `string`) => `void`
799
800A convenience method for setting prefixed styles on the Panzoom element
801
802##### Parameters
803
804| Name | Type |
805| :------ | :------- |
806| `name` | `string` |
807| `value` | `string` |
808
809##### Returns
810
811`void`
812
813#### Defined in
814
815[types.ts:289](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L289)
816
817### zoom
818
819**zoom**: (`scale`: `number`, `zoomOptions?`: ZoomOptions) => [CurrentValues](#CurrentValues)
820
821Zoom the Panzoom element to the given scale
822
823```js
824panzoom.zoom(2.2)
825panzoom.zoom(2.2, { animate: true })
826```
827
828##### Parameters
829
830| Name | Type |
831| :------------- | :---------- |
832| `scale` | `number` |
833| `zoomOptions?` | ZoomOptions |
834
835##### Returns
836
837[CurrentValues](#CurrentValues)
838
839#### Defined in
840
841[types.ts:298](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L298)
842
843### zoomIn
844
845**zoomIn**: (`zoomOptions?`: ZoomOptions) => [CurrentValues](#CurrentValues)
846
847Zoom in using the predetermined increment set in options.
848Animates by default, ignoring the global option.
849Pass `{ animate: false }` to override.
850
851```js
852panzoom.zoomIn()
853panzoom.zoomIn({ animate: false })
854```
855
856##### Parameters
857
858| Name | Type |
859| :------------- | :---------- |
860| `zoomOptions?` | ZoomOptions |
861
862##### Returns
863
864[CurrentValues](#CurrentValues)
865
866#### Defined in
867
868[types.ts:309](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L309)
869
870### zoomOut
871
872**zoomOut**: (`zoomOptions?`: ZoomOptions) => [CurrentValues](#CurrentValues)
873
874Zoom out using the predetermined increment set in options.
875Animates by default, ignoring the global option.
876Pass `{ animate: false }` to override.
877
878```js
879panzoom.zoomOut()
880panzoom.zoomOut({ animate: false })
881```
882
883##### Parameters
884
885| Name | Type |
886| :------------- | :---------- |
887| `zoomOptions?` | ZoomOptions |
888
889##### Returns
890
891[CurrentValues](#CurrentValues)
892
893#### Defined in
894
895[types.ts:320](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L320)
896
897### zoomToPoint
898
899**zoomToPoint**: (`scale`: `number`, `point`: { `clientX`: `number` ; `clientY`: `number` }, `zoomOptions?`: ZoomOptions) => [CurrentValues](#CurrentValues)
900
901Zoom the Panzoom element to a focal point using
902the given pointer/touch/mouse event or constructed point.
903The clientX/clientY values should be calculated
904the same way as a `pointermove` event on the Panzoom element's parent.
905
906```js
907panzoom.zoomToPoint(1.2, pointerEvent)
908```
909
910##### Parameters
911
912| Name | Type |
913| :-------------- | :---------- |
914| `scale` | `number` |
915| `point` | `Object` |
916| `point.clientX` | `number` |
917| `point.clientY` | `number` |
918| `zoomOptions?` | ZoomOptions |
919
920##### Returns
921
922[CurrentValues](#CurrentValues)
923
924#### Defined in
925
926[types.ts:331](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L331)
927
928### zoomWithWheel
929
930**zoomWithWheel**: (`event`: `WheelEvent`, `zoomOptions?`: ZoomOptions) => [CurrentValues](#CurrentValues)
931
932Zoom the Panzoom element to a focal point using the given WheelEvent
933
934This is a convenience function that may not handle all use cases.
935Other cases should handroll solutions using the `zoomToPoint`
936method or the `zoom` method's focal option.
937
938**Note**: the focal point zooming pan adjustment is not affected by the `disablePan` option.
939
940```js
941// Bind to mousewheel
942elem.parentElement.addEventListener('wheel', panzoom.zoomWithWheel)
943// Bind to shift+mousewheel
944elem.parentElement.addEventListener('wheel', function (event) {
945 if (!event.shiftKey) return
946 // Panzoom will automatically use `deltaX` here instead
947 // of `deltaY`. On a mac, the shift modifier usually
948 // translates to horizontal scrolling, but Panzoom assumes
949 // the desired behavior is zooming.
950 panzoom.zoomWithWheel(event)
951})
952```
953
954##### Parameters
955
956| Name | Type |
957| :------------- | :----------- |
958| `event` | `WheelEvent` |
959| `zoomOptions?` | ZoomOptions |
960
961##### Returns
962
963[CurrentValues](#CurrentValues)
964
965#### Defined in
966
967[types.ts:360](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L360)
968
969## CurrentValues
970
971### isSVG
972
973`Optional` **isSVG**: `boolean`
974
975#### Defined in
976
977[types.ts:211](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L211)
978
979### scale
980
981**scale**: `number`
982
983#### Defined in
984
985[types.ts:210](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L210)
986
987### x
988
989**x**: `number`
990
991#### Defined in
992
993[types.ts:208](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L208)
994
995### y
996
997**y**: `number`
998
999#### Defined in
1000
1001[types.ts:209](https://github.com/timmywil/panzoom/blob/22fb0b3/src/types.ts#L209)
1002
1003## Events
1004
1005The following events are available as custom events on the panzoom element using the native [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent) API.
1006Add listeners the same way you would any other event.
1007
1008```js
1009elem.addEventListener('panzoomchange', (event) => {
1010 console.log(event.detail) // => { x: 0, y: 0, scale: 1 }
1011})
1012```
1013
1014### Notes about all events
1015
1016- The event object passed as an argument to the listener will always have a `detail` object with the following properties:
1017 - The current `x` value
1018 - The current `y` value
1019 - The current `scale`
1020 - An `originalEvent` property with the original event that triggered the panzoom event, if applicable. For example, the `originalEvent` property for a `panzoomstart` event would be either a `pointerdown`, `touchstart`, or `mousedown` event.
1021- Events can be silenced when the `silent` option is set to `true`, either globally or when passed to `pan`, any `zoom` method, or `reset`.
1022- Avoid putting too much logic in these event handlers as it could effect the performance of panning or zooming.
1023
1024### `"panzoomstart"`
1025
1026Fired when the user starts a move or pinch zoom gesture on mobile.
1027
1028### `"panzoomchange"`
1029
1030Fired whenever there is a pan, zoom, or reset. Note that direct calls to `options.setTransform` do not fire this event.
1031
1032### `"panzoomzoom"`
1033
1034Fired whenever the zoom is changed by any Panzoom `zoom` method, directly or internally.
1035
1036### `"panzoompan"`
1037
1038Fired whenever the pan is changed by the `pan` method, directly or internally.
1039
1040### `"panzoomend"`
1041
1042Fired when the user finishes a move or finishes a pinch zoom gesture on mobile.
1043
1044### `"panzoomreset"`
1045
1046Fired whenever reset is called.