s-yadav / iv-viewer

A zooming and panning plugin inspired by google photos for your web images.
MIT License
451 stars 164 forks source link

Initial zoom is wrong in Container mode #7

Open oparoz opened 8 years ago

oparoz commented 8 years ago

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 commented 8 years ago

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:

s-yadav commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

Any news? :)

s-yadav commented 8 years ago

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% .