Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set bounds params #33

Open
smartcookiemedia opened this issue Jun 8, 2018 · 8 comments
Open

How to set bounds params #33

smartcookiemedia opened this issue Jun 8, 2018 · 8 comments

Comments

@smartcookiemedia
Copy link

Hi:

There doesn't seem to be any documentation on how to set a bounding conatiner for the panning.
I would love to just have it pan within the parent element. Is there a way to do this?

I tried to look through the library. This is what I guessed would be the way set the bounds, but it didn't work

bound: {
top:0,
bottom:100,
left:100,
right:100,
}

This would be very helpful if you could inform me.
Thanks!

@cibulka
Copy link

cibulka commented Jun 18, 2018

The property in config you're looking for is bounds (not "bound").

I was able to lock my panzoom element to the container like this:

const el = document.getElementById('panzoom-wrap');
const dims = el.getBoundingClientRect();
const panzoomInstance = panzoom(el, {
  bounds: {
    top: panzoomElDims.height,
    right: 0,
    bottom: 0,
    left: panzoomElDims.width,
  }
});

Edit: Bounds configuration apply for both panning and zooming. With this configuration you won't be able to zoom at all - which is definitely not the desired outcome for me. :/

Is there any way, how to set bounds only for panning (not for zooming)?

@zekedroid
Copy link

bump

Would love to know how to properly set bounds as well 👍

@renekorss
Copy link

With my PR it can be achieved with options below:

{
    bounds: true,
    boundsPadding: 1,
    boundsDisabledForZoom: true
}

@smartcookiemedia
Copy link
Author

Thanks, I will try it out

@Rim-777
Copy link

Rim-777 commented Nov 26, 2018

With my PR it can be achieved with options below:

{
    bounds: true,
    boundsPadding: 1,
    boundsDisabledForZoom: true
}

Is there the way to add bounds for zoomed picture?

@leighkendell
Copy link

Just thought I'd share my workaround for this, I played around with setting the bounds but wasn't able to maintain zooming behaviour + bounds. The main issue for me was that I was able to prevent panning past the left edge but not the right.

I ended up using:

  bounds: {
    top: 0,
    right: 0,
    bottom: 0,
    left: 0,
  }

Then added some functionality on the "panend" event to "snap" back to the right edge when panning past it.

const pzEl = document.querySelector('.pz-el');
const pzInstance = panzoom(pzEl, {
  ...
});

// Snap to the max translate value when panning past the end of the "bounds"
pzInstance.on('panend', e => {
  const { x } = e.getTransform();
  const maxTranslate = pzEl.getBoundingClientRect().width - pzEl.clientWidth;

  if (Math.abs(x) >= maxTranslate) {
    e.moveBy(-(x + maxTranslate), 0, true);
  }
});

Still not really ideal, I also tried using the .pause() and .resume() functions in the same scenario but it seems .resume() doesn't restore all previous functionality.

@rbonomo
Copy link
Contributor

rbonomo commented Jun 4, 2019

Related? #105

@rbonomo
Copy link
Contributor

rbonomo commented Jun 4, 2019

Currently, the source code needs modification to perform your expected functionality. I've opened a PR for this issue. Take a look into #105 . This example shows panzoom bounded to its parent container using my panzoom branch: https://codepen.io/rbonomo/pen/BexEPR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants