Closed GunArm closed 1 year ago
The calculation for minScale in _prepare() assumes that the image will be larger than the viewport. If it is not, it will return a minScale (as a ratio of viewPort to content) which is greater than 1. The default maxScale is 1, and the result is that with a minScale > maxScale, _computeScale(...) logic leads it to effectively alternate between maxScale and (larger) minScale.
This seems at least superficially to fix it, although I wouldn't presume to know if it might have other implications. The result for me is that an image smaller than the viewport is shown centered in the viewport and cannot zoom, which is ideal for my purposes.
} else {
content.originalWidth =
options.width || content.$element.offsetWidth;
content.originalHeight =
options.height || content.$element.offsetHeight;
}
content.minScale =
options.minScale ||
Math.min(
viewport.originalWidth / content.originalWidth,
- viewport.originalHeight / content.originalHeight
+ viewport.originalHeight / content.originalHeight,
+ options.maxScale,
+ 1
);
content.maxScale = options.maxScale;
content.currentScale = content.minScale;
content.currentWidth = content.originalWidth * content.currentScale;
content.currentHeight =
content.originalHeight * content.currentScale;
This behavior looks like a bug ))) (but on the other hand, this is not the task of this plugin - show little image)
I'm glad you made the fix for yourself. I do not have time to deal with this problem right now, but as soon as I am free, I will try to fix it and trigger you.
I totally understand that it isn't meant to show small images, this is more of an edge case, not knowing ahead of time exactly what content might go into it. No rush on my account, I just wanted to contribute back what I figured out. Thank you for making this great plugin available!
I fixed it. Pls check and close issue if all done.
Works well. Thanks again!
This script is terrific. I'm using it in a custom lightbox.
Although my main interest is to view very large images with particular interest to be seen up close, it is not known ahead of time which images will be shown in it, so some small images will inevitably also be loaded. I do not want the small images (or the large ones) to be zoomed into pixels, so the maxScale option is very handy.
However I have noticed that if the viewport is larger than the (image * maxScale), there is odd behavior:
I would have expected that if the image is smaller than the viewport (at max scale), it would be loaded at max scale and centered, with further zoom-in attempts doing nothing (because it's already at max scale).
Is this a known issue/unsupported? Or does it sound like I have done something strange?
For reference, this is effectively how I have it loaded.