views:

192

answers:

3

I have an image within a div. I scale the image with CSS transforms to 2.5 times it's original size. That works, but it overlays the containing div. I want it to stay within the containing div, is that possible?

<html>

<script language="javascript">    
    function zoom()
    {
        var myLayer = document.getElementById('layer');
        var myPhoto = document.getElementById('photo');

        myPhoto.style["-webkit-transform-origin"] = "50% 50%";
        myPhoto.style["-webkit-transform"] = "scale(2.5)";
    }

</script>

<body onload="zoom();">

<div id ="layer" style="height:700px; width:1000px; background-color:yellow;  text-align: center; vertical-align: middle;" onClick="javascript:toggleZoom();"><img id="photo" src="http://farm1.static.flickr.com/42/77156587_fa5aef2c4c_o.jpg" width="500" height="332"></div>

</body>
</html>
+1  A: 

Possibly using a CSS mask (http://webkit.org/blog/181/css-masks/) with an SVG rectangle image scaled to the appropriate size?

Antonio Salazar Cardozo
A: 

Set the image's CSS to

#image
{
    width: 100%;
}

and that's it.

I do the same thing here for the gallery pictures:

http://www.k9listener.com/gallery.html

Gary Willoughby
Hi Gary,Thanks for the tip, but that doesn't work...
Johannes Fahrenkrug
Maybe the containing div needs a width setting too.
Gary Willoughby
A: 

Have you tried just putting overflow:hidden on the containing div?

Russell Leggett
Haha! Works like a charm! Thank you!
Johannes Fahrenkrug
This will crop the image. The image is still outside of the containing div but the overflow is now hidden.
Gary Willoughby
Well I assumed that was the point, otherwise why would he scale by 2.5 instead of 2?
Russell Leggett