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

Initial zoom is wrong in Container mode #7

Open
oparoz opened this issue Mar 30, 2016 · 5 comments
Open

Initial zoom is wrong in Container mode #7

oparoz opened this issue Mar 30, 2016 · 5 comments

Comments

@oparoz
Copy link

oparoz commented Mar 30, 2016

This is a sample setup

<div style="display: block; background-position: -10000px 0px;" id="slideshow">
    <div class="imageContainer iv-container">
        <div style="display: none;" class="iv-loader"></div>
        <div class="iv-snap-view"><div class="iv-snap-image-wrap"><img style="display: inline; width: 150px; height: 150px;" class="iv-snap-image" src="https://localhost:4443/owncloud/index.php/apps/gallery/preview/53455?&amp;width=2600&amp;height=2600&amp"><div style="top: 0%; left: 0%; width: 100%; height: 100%;" class="iv-snap-handle"></div></div><div class="iv-zoom-slider"><div style="left: 0px;" class="iv-zoom-handle"></div></div></div>
        <div class="iv-image-view"><div class="iv-image-wrap"><img style="display: block; width: 918px; height: 918px; left: 164.5px; top: 0px; max-width: none; max-height: none;" class="iv-large-image" src="https://localhost:4443/owncloud/index.php/apps/gallery/preview/53455&amp;width=2600&amp;height=2600&amp"></div></div>
    </div>
</div>

and the code used

var container = $('#slideshow')
var imageContainer = container.find('.imageContainer')
var viewer = ImageViewer(imageContainer );
viewer.load(image.src);

The slideshow CSS

#slideshow {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 100000;
    display: none;
    background-color: black;
    background-position: center center;
}

The large image has the following style applied to it: width: 918px; height: 918px, but the original image is 50x50.

I've tracked it down to this line, which stretches the image to fill the container:
https://github.com/s-yadav/ImageViewer/blob/master/imageviewer.js#L608

I think there should be a limit applied, using the initial zoomValue.

@oparoz
Copy link
Author

oparoz commented Apr 1, 2016

I played with the library a bit.

By replacing

imgWidth = (imageWidth > imageHeight && contHeight >= contWidth) || ratio * contHeight > contWidth ? contWidth : ratio * contHeight;

with

// Don't stretch images to fill the container
imgWidth = imageWidth;

I get the wanted effect, which is the image showing up at it's native size or zoomed in if a parameter was passed.

Next is the snap view:

  • The image needs to be resized to match its position in the container (calculate cont/img ratio and crop to snap view)
  • When zooming, the image needs to grow to fill the container, like it is in the main view
  • Once the image in the main view is larger than the container, then the snap handle should show

@s-yadav
Copy link
Owner

s-yadav commented Apr 1, 2016

That part of code is required to contain image inside container, changing that may affect on other modes.

I am out town for few days . Will be fixing once i am back.

@oparoz
Copy link
Author

oparoz commented Apr 1, 2016

Yeah, I've noticed that the fullscreen mode has the same problem where images will be stretched to fit.
Just ping me when you're back and have time to work on this :).

@oparoz
Copy link
Author

oparoz commented Apr 20, 2016

Any news? :)

@s-yadav
Copy link
Owner

s-yadav commented Apr 21, 2016

So In ImageViewer now it behaves as backgound-size contain for a given container. And whatever size is coming at that point I am considering it as 100% zoom, which literally is not correct.
There are multiple problems which needs to be figured if image actual dimension to be considered as 100% zoom with current code.

  1. Right now only it can be zoomed when mouse is above image and not the container. But if we take the actual size of image it should happen on container as well.
  2. Zoom level can go below 100 when image actual dimension are greater that container, so minimum cap of 100 need to be removed which requires changes in lot of place.
  3. Need to figure out how to display snapview if zoom level is below 100% .

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

2 participants