CSS-Tricks / AnythingZoomer

Zoom in on images or content
https://css-tricks.github.io/AnythingZoomer/
MIT License
207 stars 45 forks source link

Different sizes images #25

Closed lbb4 closed 9 years ago

lbb4 commented 10 years ago

Hello, first of all thank you for this amazing tool. I have a doubt thought. I am trying to use the zoom with several images on my webpage but one of these images has different size. Is there any way to do it? If I call it "small" and "large" this image has the same size as the others (and therefore it is deformed), and if I call it in a different way it doesn't work. Thank you very much in advance for your response. This is driving me crazy... I have tried so many combinations to make it work. Greetings, Lara

Mottie commented 10 years ago

Hi Lara!

If you look at the documentation page you'll see that the basic HTML looks like this:

<div id="zoom">
  <div class="small">
    <img src="demo/rushmore_small.jpg" alt="small rushmore" />
  </div>
    <-- the large content can be cloned from the small content -->
   <div class="large">
      <img src="demo/rushmore.jpg" alt="big rushmore" />
   </div>
</div>

where you should set the image dimensions using css:

.zoom      { width: 500px; } 
.small img { width: 250px; height: 167px; } 
.large img { width: 500px; height: 333px; background: white; }

Ideally, the small and large image should have the same proportions (horizontal-to-vertical ratio). For example, in the css example above, both small and large image have the same (rounded off) ratio (250/167 = 1.5 & 500/333 = 1.5).

In this demo you can mess around with the image dimensions in the css to see how the sizes can be distorted/deformed.

lbb4 commented 10 years ago

Thank you for the response! But I still can't solve the problem. I understand what to do to change the size of an image, but if for example I want to put two images on my webpage, both with the zoom effect. But they have different sizes. But they both are called "small img" and "large img" in order to make the jquery works. In the CSS I can only put one size for small and one size for large. I was wondering if there is any chance of calling the second image in a different way so I can put different sizes on the CSS. The HTML should be something like this:

small image1
```
big image1
```
small image2
```
big image2
```

and CSS:

.zoom { width: 500px; } .small img { width: 250px; height: 167px; } .large img { width: 500px; height: 333px; background: white; }

But then both image1 and image2 have the same size (250px X 167px when they are small). What if I wanted the image2 to have a different size when it is small?

Mottie commented 10 years ago

Here are two solutions:

lbb4 commented 10 years ago

It worked. Thank you so so much. Greetings, Lara