Code Monkey home page Code Monkey logo

panzoom's Introduction

Panzoom

Build Status

Examples


Panzoom is a small library (~3.7kb gzipped) to add panning and zooming functionality to an element. Rather 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.

For common support questions, see the FAQ.

Browser support

Here is a list of currently supported browsers.

Mobile support

iOS, Android, and Windows Mobile are supported.

Panzoom 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 by default wherever supported.

SVG support

Panzoom supports panning and zooming SVG elements directly.

In IE11, CSS animations/transitions do not work on SVG elements, at least for the transform style. They do work in other browsers.

One could implement transitions manually in IE11 using the setTransform option and integrating a tweening library for javascript animations (such as tween.js).

Installing

With npm:

$ npm install --save @panzoom/panzoom

With yarn:

$ yarn add @panzoom/panzoom

Panzoom uses UMD and can be loaded a lot of ways.

With ES6 imports:

import Panzoom from '@panzoom/panzoom'

With commonjs or browserify:

const Panzoom = require('@panzoom/panzoom')

With an AMD loader in an anonymous module:

define(['@panzoom/panzoom'], function (Panzoom) {
  const elem = document.getElementById('panzoom-element')
  Panzoom(elem)
})

With a script tag:

<script src="/js/panzoom.js"></script>

With a script tag from a CDN:

<script src="https://unpkg.com/@panzoom/[email protected]/dist/panzoom.min.js"></script>

Usage

const elem = document.getElementById('panzoom-element')
const panzoom = Panzoom(elem, {
  maxScale: 5
})
panzoom.pan(10, 10)
panzoom.zoom(2, { animate: true })

// Panning and pinch zooming are bound automatically (unless disablePan is true).
// There are several available methods for zooming
// that can be bound on button clicks or mousewheel.
button.addEventListener('click', panzoom.zoomIn)
elem.parentElement.addEventListener('wheel', panzoom.zoomWithWheel)

FAQ

1. What is transform-origin and why is it added to the panzoom element?

  • 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.
  • HTML elements default to '50% 50%'.
  • SVG elements default to '0 0'.

2. I am using Panzoom with an <object> tag and it's not working. What's wrong?

Object 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.

3. My links aren't working! How do I enable an anchor within a panzoom element?

Add 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. Alternatively, add a reference to the element to the exclude option, or call event.stopImmediatePropagation() in an event handler on the clickable element.

A note on the async nature of Panzoom

In some cases, setting one thing and then setting another synchronously will not work as intended.

For instance, the following usually works fine.

const panzoom = Panzoom(elem)
panzoom.zoom(2)
panzoom.pan(100, 100)

However, you might find that the things start breaking when the contain option is set.

This is due to the fact that in order for Panzoom to retrieve proper dimensions, the scale needs to be painted.

If you find that things aren't looking quite right, try the following instead...

panzoom.zoom(2)
setTimeout(() => panzoom.pan(100, 100))

4. I'm using Panzoom with SVG text elements and am seeing some weird text resizing. How do I fix this?

Add text-rendering="geometricPrecision" to your <text> elements.

<text text-rendering="geometricPrecision" x="40" y="120">Hello World</text>

5. I'm using Panzoom on a canvas element that renders a PDF. How do I avoid the PDF getting blurry when scaled?

See this stackoverflow question


Documentation

Panzoom

Panzoom(elem, options?): [PanzoomObject](#PanzoomObject)

Parameters

Name Type
elem HTMLElement | SVGElement
options? Omit<[PanzoomOptions](#PanzoomOptions), "force">

Returns

[PanzoomObject](#PanzoomObject)

Defined in

panzoom.ts:59

PanzoomOptions

Includes MiscOptions, PanOptions, and ZoomOptions

MiscOptions

These 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.

animate

Optional animate: boolean (Default: false)

Whether to animate transitions

Defined in

types.ts:21

canvas

Optional canvas: boolean (Default: false)

This option treats the Panzoom element's parent as a canvas. Effectively, Panzoom binds the down handler to the parent instead of the Panzoom element, so that pointer events anywhere on the "canvas" moves its children. See issue #472.

Note: setting this option to true also changes where the cursor style is applied (i.e. the parent).

Defined in

types.ts:32

duration

Optional duration: number (Default: 200)

Duration of the transition (ms)

Defined in

types.ts:34

easing

Optional easing: string (Default: "ease-in-out")

CSS Easing used for transitions

Defined in

types.ts:36

exclude

Optional exclude: Element[] (Default: [])

Add elements to this array that should be excluded from Panzoom handling. Ancestors of event targets are also checked. e.g. links and buttons that should not propagate the click event.

Defined in

types.ts:43

excludeClass

Optional excludeClass: string (Default: "panzoom-exclude")

Add this class to any element within the Panzoom element that you want to exclude from Panzoom handling. That element's children will also be excluded. e.g. links and buttons that should not propagate the click event.

Defined in

types.ts:50

force

Optional force: boolean

force should be used sparingly to temporarily override and ignore options such as disablePan, disableZoom, and panOnlyWhenZoomed. This option cannot be passed to the Panzoom constructor or setOptions (to avoid setting this option globally).

// Overrides disablePan and panOnlyWhenZoomed
panzoom.pan(50, 100, { force: true })
// Overrides disableZoom
panzoom.zoom(1, { force: true })

Defined in

types.ts:66

handleStartEvent

Optional handleStartEvent: (event: Event) => void (Default: (e: Event) => { e.preventDefault() e.stopPropagation() })

On the first pointer event, when panning starts, the default Panzoom behavior is to call event.preventDefault() and event.stopPropagation() on that event. The former is almost certainly a necessity; the latter enables Panzoom elements within Panzoom elements.

But there are some cases where the default is not the desired behavior. Set this option to override that behavior.

// Only call preventDefault()
Panzoom(elem, {
  handleStartEvent: (event) => {
    event.preventDefault()
  }
})
// Do nothing.
// This can change dragging behavior on mobile.
Panzoom(elem, {
  handleStartEvent: () => {}
})
Parameters
Name Type
event Event
Returns

void

Defined in

types.ts:91

noBind

Optional noBind: boolean

Skip binding the default Panzoom event listeners

Defined in

types.ts:95

origin

Optional origin: string

Change this at your own risk. The transform-origin is the origin from which transforms are applied. Default: '50% 50%' for HTML and '0 0' for SVG. The defaults are set because changing the transform-origin on SVG elements doesn't work in IE.

Changing this should work with many things, but it will break focal point zooming, which assumes the defaults are set to do the more complicated calculations.

And again, changing this for SVG in IE doesn't work at all.

Defined in

types.ts:109

overflow

Optional overflow: string (Default: "hidden")

The overflow CSS value for the parent. Defaults to 'hidden'

Defined in

types.ts:111

pinchAndPan

Optional pinchAndPan: boolean (Default: false)

Set to true to enable panning during pinch zoom. Note: this is zooming to a point and panning in the same frame. In other words, the zoom has not yet painted and therefore the pan is working with old dimensions. Essentially, it may be best to avoid using this option when using contain.

Related issues: #512 #606

Defined in

types.ts:124

setTransform

Optional setTransform: (elem: HTMLElement | SVGElement, __namedParameters: CurrentValues, _options?: PanzoomOptions) => void

Set the transform using the proper prefix

Override the transform setter. This is exposed mostly so the user could set other parts of a transform aside from scale and translate. Default is defined in src/css.ts.

// This example always sets a rotation
// when setting the scale and translation
const panzoom = Panzoom(elem, {
  setTransform: (elem, { scale, x, y }) => {
    panzoom.setStyle('transform', `rotate(0.5turn) scale(${scale}) translate(${x}px, ${y}px)`)
  }
})
Parameters
Name Type
elem HTMLElement | SVGElement
__namedParameters CurrentValues
_options? PanzoomOptions
Returns

void

Defined in

types.ts:128

silent

Optional silent: boolean

Silence all events

Defined in

types.ts:130

startScale

Optional startScale: number (Default: 1)

Scale used to set the beginning transform

Defined in

types.ts:136

startX

Optional startX: number (Default: 0)

X Value used to set the beginning transform

Defined in

types.ts:132

startY

Optional startY: number (Default: 0)

Y Value used to set the beginning transform

Defined in

types.ts:134

touchAction

Optional touchAction: string (Default: "none")

This value is used to set touch-action on both the Panzoom element and its parent. It is needed because that the native scroll on mobile interferes with panning and pinch zooming. Set this to empty string to re-enable scrolling on mobile, but note that both scrolling and panning cannot work at the same time.

Defined in

types.ts:146

PanOptions (includes MiscOptions)

contain

Optional contain: "inside" | "outside"

Contain the panzoom element either inside or outside the parent. Inside: The panzoom element is smaller than its parent and cannot be panned to the outside. Outside: The panzoom element is larger than its parent and cannot be panned to the inside. In other words, no empty space around the element will be shown.

Note: the containment pan adjustment is not affected by the disablePan option.

Defined in

types.ts:165

cursor

Optional cursor: string (Default: "move")

The cursor style to set on the panzoom element

Defined in

types.ts:167

disablePan

Optional disablePan: boolean (Default: false)

Disable panning functionality. Note: disablePan does not affect focal point zooming or the contain option. The element will still pan accordingly.

Defined in

types.ts:173

disableXAxis

Optional disableXAxis: boolean (Default: false)

Pan only on the Y axis

Defined in

types.ts:175

disableYAxis

Optional disableYAxis: boolean (Default: false)

Pan only on the X axis

Defined in

types.ts:177

panOnlyWhenZoomed

Optional panOnlyWhenZoomed: boolean (Default: false)

Disable panning while the scale is equal to the starting value

Defined in

types.ts:181

relative

Optional relative: boolean (Default: false)

When passing x and y values to .pan(), treat the values as relative to their current values

Defined in

types.ts:179

roundPixels

Optional roundPixels: boolean

Round x and y values to whole numbers. This can help prevent images and text from looking blurry, but the higher the scale, the more it becomes necessary to use fractional pixels. Use your own judgment on how much to limit zooming in when using this option.

Defined in

types.ts:190

ZoomOptions (includes MiscOptions)

disableZoom

Optional disableZoom: boolean (Default: false)

Disable zooming functionality

Defined in

types.ts:195

focal

Optional focal: Object

Zoom to the given point on the panzoom element. This point is expected to be relative to the panzoom element's dimensions and is unrelated to the parent dimensions.

Type declaration

Name Type
x number
y number

Defined in

types.ts:202

maxScale

Optional maxScale: number (Default: 4)

The maximum scale when zooming

Defined in

types.ts:206

minScale

Optional minScale: number (Default: 0.125)

The minimum scale when zooming

Defined in

types.ts:204

step

Optional step: number (Default: 0.3)

The step affects zoom calculation when zooming with a mouse wheel, when pinch zooming, or when using zoomIn/zoomOut

Defined in

types.ts:208

PanzoomObject

These methods are available after initializing Panzoom.

bind

bind: () => void

Bind the default down, move, and up event listeners to the Panzoom element. This does not normally need to be called. It gets called by default when creating a new Panzoom object, but can be skipped with the noBind option.

const panzoom = Panzoom(elem, { noBind: true })
// ...
panzoom.bind()
Returns

void

Defined in

types.ts:235

destroy

destroy: () => void

Remove all event listeners bound to the the Panzoom element

Returns

void

Defined in

types.ts:237

eventNames

eventNames: Object

This object exposes the event names used by Panzoom, depending on the current browser's support for Pointer or Touch events.

Type declaration

Name Type
down string
move string
up string

Defined in

types.ts:243

getOptions

getOptions: () => PanzoomOptions

Returns a copy of the current options object

Returns

PanzoomOptions

Defined in

types.ts:249

getPan

getPan: () => { x: number ; y: number }

Get the current x/y translation

Returns

Object

Name Type
x number
y number

Defined in

types.ts:245

getScale

getScale: () => number

Get the current scale

Returns

number

Defined in

types.ts:247

handleDown

handleDown: (event: PointerEvent) => void

handleDown, handleMove, and handleUp are the exact event handlers that Panzoom binds to pointer events. They are exposed in case you prefer to bind your own events or extend them. Note that move and up are bound to the document, not the Panzoom element. Only the down event is bound to the Panzoom element. To avoid double-binding, also set noBind to true.

const panzoom = Panzoom(elem, { noBind: true })
elem.addEventListener('pointerdown', (event) => {
  console.log(event)
  panzoom.handleDown(event)
})
document.addEventListener('pointermove', panzoom.handleMove)
document.addEventListener('pointerup', panzoom.handleUp)
Parameters
Name Type
event PointerEvent
Returns

void

Defined in

types.ts:271

handleMove

handleMove: (event: PointerEvent) => void

Parameters
Name Type
event PointerEvent
Returns

void

Defined in

types.ts:272

handleUp

handleUp: (event: PointerEvent) => void

Parameters
Name Type
event PointerEvent
Returns

void

Defined in

types.ts:273

pan

pan: (x: string | number, y: string | number, panOptions?: PanOptions) => [CurrentValues](#CurrentValues)

Pan the Panzoom element to the given x and y coordinates

// Translates the element to 50px, 100px
panzoom.pan(50, 100)
// Pans the element right 10px and down 10px from its current position
panzoom.pan(10, 10, { relative: true })
Parameters
Name Type
x string | number
y string | number
panOptions? PanOptions
Returns

[CurrentValues](#CurrentValues)

Defined in

types.ts:284

reset

reset: (resetOptions?: PanzoomOptions) => [CurrentValues](#CurrentValues)

Reset the pan and zoom to startX, startY, and startScale. Animates by default, ignoring the global option. Pass { animate: false } to override. Reset ignores the disablePan, disableZoom, and panOnlyWhenZoomed options. Pass { force: false } to override.

panzoom.reset()
panzoom.reset({ animate: false })
Parameters
Name Type
resetOptions? PanzoomOptions
Returns

[CurrentValues](#CurrentValues)

Defined in

types.ts:297

resetStyle

resetStyle: () => void

Reset the styles set on the Panzoom element and its parent (such as overflow, cursor, etc.)

panzoom.resetStyle()
Returns

void

Defined in

types.ts:306

setOptions

setOptions: (options?: PanzoomOptions) => void

Change any number of options on a Panzoom instance. Setting some options will have side-effects. For instance, changing the cursor option will also set the cursor style.

const panzoom = Panzoom(elem, { cursor: 'move' })
// ...
panzoom.setOptions({ cursor: 'default' })
Parameters
Name Type
options? PanzoomOptions
Returns

void

Defined in

types.ts:319

setStyle

setStyle: (name: string, value: string) => void

A convenience method for setting prefixed styles on the Panzoom element

Parameters
Name Type
name string
value string
Returns

void

Defined in

types.ts:321

zoom

zoom: (scale: number, zoomOptions?: ZoomOptions) => [CurrentValues](#CurrentValues)

Zoom the Panzoom element to the given scale

panzoom.zoom(2.2)
panzoom.zoom(2.2, { animate: true })
Parameters
Name Type
scale number
zoomOptions? ZoomOptions
Returns

[CurrentValues](#CurrentValues)

Defined in

types.ts:330

zoomIn

zoomIn: (zoomOptions?: ZoomOptions) => [CurrentValues](#CurrentValues)

Zoom in using the predetermined increment set in options. Animates by default, ignoring the global option. Pass { animate: false } to override.

panzoom.zoomIn()
panzoom.zoomIn({ animate: false })
Parameters
Name Type
zoomOptions? ZoomOptions
Returns

[CurrentValues](#CurrentValues)

Defined in

types.ts:341

zoomOut

zoomOut: (zoomOptions?: ZoomOptions) => [CurrentValues](#CurrentValues)

Zoom out using the predetermined increment set in options. Animates by default, ignoring the global option. Pass { animate: false } to override.

panzoom.zoomOut()
panzoom.zoomOut({ animate: false })
Parameters
Name Type
zoomOptions? ZoomOptions
Returns

[CurrentValues](#CurrentValues)

Defined in

types.ts:352

zoomToPoint

zoomToPoint: (scale: number, point: { clientX: number ; clientY: number }, zoomOptions?: ZoomOptions) => [CurrentValues](#CurrentValues)

Zoom the Panzoom element to a focal point using the given pointer/touch/mouse event or constructed point. The clientX/clientY values should be calculated the same way as a pointermove event on the Panzoom element's parent.

panzoom.zoomToPoint(1.2, pointerEvent)
Parameters
Name Type
scale number
point Object
point.clientX number
point.clientY number
zoomOptions? ZoomOptions
Returns

[CurrentValues](#CurrentValues)

Defined in

types.ts:363

zoomWithWheel

zoomWithWheel: (event: WheelEvent, zoomOptions?: ZoomOptions) => [CurrentValues](#CurrentValues)

Zoom the Panzoom element to a focal point using the given WheelEvent

This is a convenience function that may not handle all use cases. Other cases should handroll solutions using the zoomToPoint method or the zoom method's focal option.

Notes:

  • the focal point zooming pan adjustment is not affected by the disablePan option.
  • animate should not be used when zooming with the wheel, and is therefore always disabled.
// Bind to mousewheel
elem.parentElement.addEventListener('wheel', panzoom.zoomWithWheel)
// Bind to shift+mousewheel
elem.parentElement.addEventListener('wheel', function (event) {
  if (!event.shiftKey) return
  // Panzoom will automatically use `deltaX` here instead
  // of `deltaY`. On a mac, the shift modifier usually
  // translates to horizontal scrolling, but Panzoom assumes
  // the desired behavior is zooming.
  panzoom.zoomWithWheel(event)
})
Parameters
Name Type
event WheelEvent
zoomOptions? ZoomOptions
Returns

[CurrentValues](#CurrentValues)

Defined in

types.ts:396

CurrentValues

isSVG

Optional isSVG: boolean

Defined in

types.ts:219

scale

scale: number

Defined in

types.ts:218

x

x: number

Defined in

types.ts:216

y

y: number

Defined in

types.ts:217

Events

The following events are available as custom events on the panzoom element using the native CustomEvent API. Add listeners the same way you would any other event.

elem.addEventListener('panzoomchange', (event) => {
  console.log(event.detail) // => { x: 0, y: 0, scale: 1 }
})

Notes about all events

  • The event object passed as an argument to the listener will always have a detail object with the following properties:
    • The current x value
    • The current y value
    • The current scale
    • 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.
  • Events can be silenced when the silent option is set to true, either globally or when passed to pan, any zoom method, or reset.
  • Avoid putting too much logic in these event handlers as it could effect the performance of panning or zooming.

"panzoomstart"

Fired when the user starts a move or pinch zoom gesture on mobile.

"panzoomchange"

Fired whenever there is a pan, zoom, or reset. Note that direct calls to options.setTransform do not fire this event.

"panzoomzoom"

Fired whenever the zoom is changed by any Panzoom zoom method, directly or internally.

"panzoompan"

Fired whenever the pan is changed by the pan method, directly or internally.

"panzoomend"

Fired when the user finishes a move or finishes a pinch zoom gesture on mobile.

"panzoomreset"

Fired whenever reset is called.

panzoom's People

Contributors

agcolom avatar avgeeklucky avatar breakthestatic avatar carlos22 avatar dependabot[bot] avatar greenkeeper[bot] avatar iongion avatar jcnventura avatar karlito40 avatar timmywil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

panzoom's Issues

Pan Left, Right, Up and Down by Event

Please add support for an event that will move the item, like this:

$('.panLeft').click(function() {
 $("#panzoom").panzoom("panTo", -10, 10 , true);
 // Should move the item 10 units to the left and 10 units down
});

Viewport being 100% width and 80% height

Hello again :-)

Is it possible to have the following scenario (it is for mobile devices..):
The viewport being width 100% and height 80% and the panning/zooming image to be contained that area, but with its minimum dimension not to be smaller than the viewport dimensions.. That is, in it's initial state the image would be scaled accordingly to fit that box.. and never being smaller than it.

Any ideas?

Thanks a lot.

Enforce inverted containment automatically

We can calculate the minimum scale required to ensure the panzoom element is large enough to keep the parent container invisible. This may not always be ideal, but it could be an option with the default set to true.

feature: inertia on drag

It would be cool to have an option for a bit of inertia when you're dragging just to make it flow a bit smoother - similar to the effect you get dragging a finger on mobile. A little "spliney" rather than the very precise drag you get currently.

I'm not sure this would be possible for devs to emulate using the events you currently generate, but if you think it is, let me know!

Thanks - John
(Loving the resetDimensions fix you did too)

Find location of a point after zooming

Hi,

First of all, thanks for the great plug-in!

I'm running into a problem with embedding an SVG document like this in my HTML:

<div id="svgdiv">
    <object type="image/svg+xml" data="mysvg.svg"></object>
</div>

Now, I'm attaching the panzoom to the outer div, which means I'll get panning and zooming on the SVG as well.
However, I'm attaching behavior to elements inside the SVG document as well.
I'm showing a popover in place when you hover over an element inside the SVG document. When no zooming or panning has taken place, the event gives me the correct coordinates for this popover.

Once zoomed and/or panned however, the coordinates do not seem to be correct (ie: they're still the old values). I tried using the transformation matrix to get the calculated position but I can't seem to figure it out.

Do you have any idea on how to do this?

Overwrite touchSupported

It would be nice to have an option that overwrites the touchSupported value.

My application is based on jQuery mobile and PhoneGap, I don't target any desktop browsers without touch support.

Question: feature-detection rather than browser-detection

Thanks for a great plugin!

I'd like to use feature-detection rather than browser-detection for deciding whether the controls should be displayed or not.

What's missing in IE <= 8 which makes this plugin non-functional?

Thanks.

Distinguishing taps or clicks from drags or moves

This is not a bug, just a (hopefully) helpful hint for other panzoom users...

Since all clicks, taps, moves or drags on the panzoom object trigger the "onEnd" option, and clicks or taps will return a "false" to the changed parameter, you can do this:

onEnd: function(e,panzoom,matrix,changed) {
   if (changed === false) {
      // call function to deal with clicks or taps
   } else {
      // call function to work with drags or touch moves
   }
},

This is probably very obvious to most of y'all, but took me awhile to figure out. Hope this saves someone a bit of time.

Is there a way to know the current zoom?

Hi, I'm using your plugin and it works great! Thanks for your work. But while I was working with it I needed to know the current zoom to know if it's active or it's have been reset to the initial zoom. I've checked the object I get with the instance() method, but I can't find it.

Is there any other way to simply get the current state of the plugin?
Thanks

Disabling panning stops custom cursor declarations

I suspect that this may be deliberate to get rid of the move cursor.

My use case is that I want to simulate a disabled state where I can click on a container and to turn on panning and zooming. I want to set the cursor to pointer while I'm in this disabled state to show that you can interact with it, but while panning is disabled you can't customise the cursor. See: http://codepen.io/adrianosmond/pen/cKbxB

<a> links inside the panzoom object

Hello,
I have inside the panzoom container ".map", a div with a

and some navigation points with a link .... All work fine in desktop (the links click fine), but in mobile, the links do not work, I can only pan and zoom the container.
Any suggestions

containt="invert" and pan the wrapper programmatically

If i set contain property on "invert", then i can't pan my container programmatically.
This is my code to pan the container:
$(this).panzoom("pan", -81, 54, { relative: true });
When the contain property is false, it's working properly, but in "invert" mode, it's not working any more.

Thanks For your amazing plugin.

How to control events ?

Hi !
Thanks a lot for your plugin, it's really cool.

I'm trying to control events by scale levels.

This is an exemple
http://jsfiddle.net/Dgbdd/1/

I just want that, when the zoom scale is on 1,2,3,4, it will shows differents phrases on the right.
How can i say that ?

Thanks a lot !

Finding location of click, or <a> tags

Hello, thank you VERY much for creating 'jquery.panzoom'.

I would like to have clickable/touchable areas in my SVG. I have tried the following:

  • tags inside of the SVG markup. [ These do not appear to function with jquery.panzoom ].
  • I have altered panzoom.js slightly to obtain the event.pageX/pageY coordinates, and use the 4th and 5th elements of the matrix to offset the coordinates. This yields usable results in Windows/Chrome, but iOS Safari and Android yield odd inconsistent coordinates.

Is there a built-in way to make areas clickable, and/or allow tags?

SVG in OBJECT not suported?

Hello, I'd like to use this script in an upcoming project. There we have SVG embedded in HTML with the element instead of (Because SVG-IMG cannot be interactive the way we need it).

I tried your script with the two methods

        < object data="Maps/mun-orig-ai.svg" id="floorplan-svg" ></ object>
        < img src="Maps/mun-orig-ai.svg" id="floorplan-svg" />

but only the img would respond to calls like $('#floorplan-svg').panzoom('zoom').

Could this be extended to work with OBJECT?

Ability to animate pan feature

Thanks for adding the pan feature!
Could you please extend it to support animation, just as "reset" already does?
pan(x, y, [options], [animate])

Arguments
x - {Number}: X Coordinate
y - {Number}: Y Coordinate
options - {Object}: These options are also passed along to setMatrix
animate {Boolean}: Whether to animate the pan (default: true)

$('.panLeft').click(function() { // animated pan to the specified coordinates $("#panzoom").panzoom("pan", -250, 100, {relative: true}, true); });

Scrollbars for container

First of all this plugin rocks. I don't know if I would classify this as an issue so if this is wasting time I apologize. As I've had people use this on the desktop for essentially a document editor they would like to still have scroll bars on the parent div / container (essentially panning by scrolling). I am willing to dive into the code and do it myself but I was wondering if there are any "word to the wise" in doing so or if there is an easy work around already for this already.

Scroll wheel opts.middle usage

I'm having quite a hard time setting up zooming by mousewheel. I can zoom/zoomout just fine by binding to the mousewheel event and executing

$panzoom.panzoom("zoom", true, { middle: $mid });

The problem is getting it to gravitate to the mouse location. What "point" should the middle option be? Should it be a point relative to the div i'm zooming? Should it be relative to the middle of the div? Maybe a specific example of that would be awesome!

ios pan

hey,

the script works fine on desktop
but on my ipad mini i cant pan.
when i touch it it moves the hole site.

my version is 0.6 with jquery 1.9.3 and jquery ui 1.10.3

Issue with FireFox Browsers

This amazing plug-in has problem with Fire Fox.it's not a technical problem,it's a graphical problem.
When you pan the container , the items lose their shapes.

Thank you for your attention

Add demos for all options

I need to make more demos for the different uses of Panzoom. Some of these include:

  • contain: true
  • contain: 'invert'
  • focal point zooming (when finished)
  • programmatic transitions

These demos should include both HTML and SVG and be responsive.

focal on mouse click

If i want zoom on exactly clicked point, what should i do?
You have focal on zoom for mouse wheel but i need it on click event.

Thanks in advanced.

Viewport of image

Is it possible to implement a smaller viewport that is a different aspect ratio than the original image? Let's say for instance I have an image that's 1800x1600 and I create an inverted panzoom instance with a minscale of 1 and maxscale of 2. I set the initial state to zoom so my 'viewport' is 900x800 zoomed. Is it possible to create a viewport that will contain the image to something like 700x450? I've played with various settings but I obviously don't have enough of a clue to figure it out.

$(".panzoom").panzoom({
$zoomIn: $(".zoom-in"),
$zoomOut: $(".zoom-out"),
$zoomRange: $(".zoom-range"),
$reset: $(".reset"),
contain: "invert",
minScale: 1,
maxScale: 2,
cursor: "arrow"
}).panzoom("zoom");

    $(".panzoom").panzoom("zoom", true);

Restoring form events

Hi, I was working with the library and suddenly found that some select box inside the panzoom area had stopped working.

As I'm in some hurry, I've fixed adding in the _bind function a conditional to disable the preventDefault and the stopPropagation when the event target.tagName is the select, and it works (if you pan when the select is open the dropdow don't pan, but I'll have to live with that), but there must be a better way.

Maybe you knew about this. I'll try some other way later at home when I have more time

Speed up zoom movements on mobile

Zooming on mobile (via pinch) seems like hard work by default and I was wondering how I could speed up zooming, I tried the following:

clickedInfographic.panzoom({
                        contain: 'invert',
                        minScale: 1,
                        increment: 2,
                        duration: 5,
                        transition: false
                    });

But it didn't make a lot of difference, anything else I can try?

LOVE this library btw thank you :D

Should the default zoom actions zoom to the center of the container element?

At the moment, zooming using buttons passed in as $zoomIn and $zoomOut options seems to set the focal point of the zoom to be the center of the element that is being panzoom-ed. Would a more natural behaviour be to set the focal point of the transition to be the center point of the container element?

The current implementation gives the impression that panning is taking place as well as zooming: http://codepen.io/adrianosmond/pen/oqszy

Hello

Hi, i`m just asking if i can zoom a svg with click but the zone where i click to be centred?

Getting the SVG drawing element that was touched or clicked

First of all, awesome plugin! Thanks for making this!

I have some circles inside my SVG that I want to take action on when touched/clicked. I don't want to take action on them if they're touched as part of a pan or pinch gesture.

I have tried following approach, however I can't see any way that I would actually get a reference to the drawing element that was clicked with these arguments. I only get a reference to the SVG itself:

onEnd: function(e,panzoom,matrix,changed) {
if (changed === false) {
// call function to deal with clicks or taps
// don't know what was actually clicked though
}

As a result I am using this approach which basically works, but at the end of a pan or zoom event this code always gets fired. I end up taking action on the circle even though the user probably didn't really want to select it--they were just panning.

$panZoom.on("click touchend", function (e) {
if (e.target.localName == "circle") {
//they clicked a circle--do something
}
});

Thanks for the help!

How is contain supposed to work?

I just updated to 1.4.2 after seeing you've made changes in the containment code. I'm not really sure how that is supposed to work. I changed your demo and passed in contain:true as an option so I expected a scaled down tiger to always be contained within the parent

element. IOW, moving the tiger left would stop at the left edge of te
element. Moving right would stop when the right edge of the tiger met the right edge of the
. Instead, it moves within a constrained horizontal center of the
element and the tiger cannot be moved top/bottom. Is that how contain is supposed to work? I tried "invert", but that didn't help me understand what's going on.

If that is how it supposed to work, is there any way to stop a pan from starting? I'd like to be able to zoom a photo up larger than a container then not allow the photo to go beyond the edges of the container (e.g. you'd never be able to see any area of the container).

Thanks!

Double tap to zoom

I presume it doesn't currently have support for double tapping to zoom (the default action for images on iOS), to implement this would I have to setup a listener for it and trigger the zooming manually?

stop the panzoom on demand

Hi
Thanks for the great plug , works great
I have it set on a div
but in the panzoom div , I have elements that are draggable and resizable
so I'd like to stop the panzooming when these events start and turn it back on on end
I tried destroy and reinitialising panzooming
but the result isn't good
is there a right way to do this ?
Thanks for the help
Tibor

Touch events ios positioning issue zoom and pan horizontal?

Hi Timmy and thanks for the great work!

No problem on browsers but on ios I have a serious bug (spent 3 days now so crying for help):

--- I instantiate panzoom ---
$("#panzoom").panzoom(
{
$zoomIn: $("#zoomin").on("click"),
$zoomOut: $("#zoomout").on("click"),
maxScale: 1.2,
minScale: largestSide/backgroundSize,
increment: 0.05
});
// Compute starting zoom
$("#panzoom").panzoom("zoom",largestSide/backgroundSize);
// Make panzoom draggable
$("#panzoom").draggable({scroll: false});
// Reposition
reposition();
....

--- I use jquery animate to reposition my image after initial zoom ---
function reposition()
{
dragtoplimit = screenh-(backgroundSize_zscale);
dragleftlimit = (screenw-thumbw)-(backgroundSize_zscale);
if ($("#panzoom").offset().top > 0)
{
$("#panzoom").animate({ "top": "-="+$("#panzoom").offset().top+"px" }, "fast" );
}
....

On ios I'm not sure what's happening with the viewport and the jquery positioning but when I try to pan or zoom the image I stay stuck on the initial-zoom Y-positioning??

What am I doing wrong? please help, I don't want to rewrite drag or touch events because I'm sure you did it well but I am missing something.

Nicolas.

Zoom to the top-left corner

I'd like the focal point be the top-left corner of the image, instead of the center.
I wrote this code - which works fine:

$(image).panzoom({
   $zoomIn: $("#zoom_in_btn"),
   $zoomOut: $("#zoom_out_btn"),
   focal: {clientX:0, clientY:0},
   animate: true,
   contain: 'invert'
});

My Question: is this the "best" way of achieving this?

Option to control child element by interacting with parent

Hi, I found this plugin recently and find it extremely useful; thanks very much for creating it. However, the app I'm developing is designed in such a way that I am in need a particular feature for the plugin.

I'll do my best to explain my request:

My goal is to have a container element that receives touch input using the plugin, as usual. However, the container element will not move/scale in response. Instead, a child element (within the container) will move/scale. You see, I'm trying to create an infinitely pan-able and scaleable canvas, in which the child element will not necessarily be within the boundaries of the container.

Would it be possible/feasible to add this functionality?

Thanks very much,
Caleb

Zooming doesn't follow the fingers

When zooming at the top of a long image, the image disappears down the page, because it zooms around the center of the image, not where my fingers are placed on screen. Would be nice if it felt like I was "holding" the image with my fingertips (like zooming in a map application does).

Resizing parent and contain=invert

Hi Timmy - this is an awesome lib, thank you.

I have an issue when the parent resizes and lets you drag way beyond where you should be able to with the child given it's in a contained mode.

I've modified your contain / invert example if you can take a look.

http://codepen.io/anon/pen/xrGki

If you scroll the tiger so you're looking at the bottom right corner, then click "Resize Up" you'll see a lot of red at the bototm. Resize down again and you'll get red on the sides.

I'm not sure whether this is something that requires a mod in your code, I've tried all sorts of things on my side of the fence to counter it but have yet to crack it.

In my app I start off with a small div and have a "resize" to full screen which fills the client window, but then it lets you drag the child way off the viewport.

Thanks in advance - John

"increment" option on zoom range is not being obeyed

Hi,

On line 818 of your uncompressed plugin, you have hard-coded the zoom increment at 0.05. This, I think, should be set to "options.increment". Once I changed this line on my copy to reflect that, the range control acted as expected.

Fabulous plugin, thanks for writing and maintaining it.

bound pan feature to image

I have been trying to bound panning to the image only but it keeps going beyond it. I am using a jpeg image instead of a SVG. I am new to jquery, could you guide me on how to do this?

zoom focal on contain invert panzooms

Some experimenting has me suspecting that "contain invert" panzooms might need to have this line (roughly near line 600):

var offsetM = new Matrix( 1, 0, o.left - this.$doc.scrollLeft(), 0, 1, o.top - this.$doc.scrollTop() );

changed to this:

var offsetM = new Matrix( 1, 0, 0, 0, 1, 0 );

The latter keeps the focal point where I specify (in this case, passing the values via "clientX" and "clientY" on the zoom method). The original introduces an X, Y error which is related to the parent offset values.

Thanks again for your continued efforts.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.