question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I init panzoom globally?

See original GitHub issue

Hello, how can I init panzoom globally? I’m trying to implement this plugin to work with flickity.js, so I’ve forked this plugin a bit. I have 2 different events on 2 different buttons, and it will work bad(e.g. animations doesn’t work, can’t destroy panzoom on zoomout event, etc) if I init panzoom twice, like I did for now:

proto.inZoom = function() { // This is forked line from flickity-fullscreen.js, line 64
  this._changeZoom( true );
  this.focus();

  const elem = document.querySelector('.is-selected')
  const panzoom = Panzoom(elem, {
    maxScale: 3,
    minScale: 1,
    panOnlyWhenZoomed: true,
    overflow: 'visible',
    contain: 'outside',
  })
  panzoom.pan(0, 0)
  panzoom.zoom(3, { animate: true})

  this.element.addEventListener('click', panzoom.zoomIn)
};

proto.outZoom = function() {
  this._changeZoom( false );

  const elem = document.querySelector('.is-selected')

  const panzoom = Panzoom(elem, {
    maxScale: 3,
    minScale: 1,
    panOnlyWhenZoomed: true,
    overflow: 'visible',
  })
  panzoom.pan(0, 0)

  this.element.addEventListener('click', panzoom.zoomOut)
};

Related issue: #480

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
timmywilcommented, Jul 23, 2021

Panzoom seemed to already be available globally in your fiddle. However, since you are using UMD, I suggest adding Panzoom as one of your dependencies.

https://jsfiddle.net/timmywil/1jxgak02/9/

I went ahead and edited your zoom functions as well to fit what I think you’re going for.

0reactions
YOBA1112commented, Aug 17, 2021

Thanks for the help! I managed to fix this problem by creating function which initializes panzoom. See this fiddle.

Read more comments on GitHub >

github_iconTop Results From Across the Web

panzoom/README.md at main - GitHub
One exception is force , which can only be passed to methods like pan() or zoom() , but not Panzoom() or setOptions() as...
Read more >
How to set Jquery panzoom default zoom? - Stack Overflow
Either call zoom() right after initialization $elem.panzoom("zoom", 1.1, {silent: true}) // +10%. Or set a value for startTransform in the ...
Read more >
@panzoom/panzoom - npm
Start using @panzoom/panzoom in your project by running `npm i @panzoom/panzoom`. ... or setOptions (to avoid setting this option globally).
Read more >
Add Data, Pan, Zoom, Identify - CGA Web Maps
Add Data, Pan, Zoom, Identify. We must first add a layer of data to use the map navigation controls in QGIS. Go to...
Read more >
Pan/Zoom to selected features in Python Add-in
Pan/Zoom to selected features in Python Add-in ... """Implementation for MRPAssistant_addin.panbutton (Button)""" def __init__(self): ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found