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

Zoom overpasses the limit #9

Open
mauro-balades opened this issue May 11, 2022 · 2 comments
Open

Zoom overpasses the limit #9

mauro-balades opened this issue May 11, 2022 · 2 comments

Comments

@mauro-balades
Copy link

Screenshot_20220511_173038

you can go as much as you want by zooming out even tho the scrolling bar says it is at its limit.

@andimeier-ch
Copy link

Same problem for me. Is there a way to define a minmial Ratio? (like the maxRatio parameter)

@daveherman71
Copy link

For me this issue only seems to occur with the option fill: "contain" and you click the zoomer buttons (the slider seems to behave itself).

This is how I accomplished the minimum ratio check.

First: Define a function that will check to see if we are below the minimum ratio or not.

const checkMinRatio = (instance) => {

  let minRatio = 1,
    currentRatio = instance.ratio,
    zoomerIn = document.querySelector(instance.options.zoomer.inEl),
    zoomerOut = document.querySelector(instance.options.zoomer.outEl);

  if (currentRatio >= minRatio)
  {
    // Change the cursor from default to move
    instance.element.style.cursor = currentRatio > minRatio ? "move" : "default";

    // Clicking the zoomer button is async so set it's disable state later
    setTimeout(function() {
      if (currentRatio <= minRatio) zoomerOut.classList.add("zoomist-zoomer-disable");
      else zoomerOut.classList.remove("zoomist-zoomer-disable");
    }, 1);
  }
  else
  {
    // Zoom back up to the minRatio
    instance.zoomTo(minRatio);
  }
}

Then: Initialize Zoomist so that the ready and zoom events call the function, for example:

new Zoomist(".imageZoom", {
  fill: "contain",
  height: 400,
  maxRatio: 8,
  wheelable: false,  // Disabled to prevent zooming while scrolling the page
  slider: {
    el: ".imageZoom-slider",
    direction: "horizontal"
  },
  zoomer: {
    inEl: ".imageZoom-zoomer--in",
    outEl: ".imageZoom-zoomer--out",
    disableOnBounds: true
  },
  on: {
    ready() { checkMinRatio(this); },
    zoom(ratio) { checkMinRatio(this); }
  }
});

Hope this helps.

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

3 participants