I am trying to create a zoom-in functionality for a container with CSS3 Transform (scale) and all seems to work nicely, but when the image is scaled, the overflow only covers a part of the image, leaving the top left part out of the overflow.
Code is as follows:
HTML:
<div class="outer">
<img id="profile" src="http://flickholdr.com/300/200/" />
</div>
<button class="zoom orig">Original</button>
<button class="zoom x2">x2</button>
<button class="zoom x4">x4</button>
CSS:
.outer { width: 500px; height: 500px; overflow: auto; text-align: center; background: #eee; }
.outer:before { content: ''; display: inline-block; vertical-align: middle; height: 100%; }
.outer img { vertical-align: middle; }
.scale_x2 { -webkit-transform: scale(2); -moz-transform: scale(2); -ms-transform: scale(2); -o-transform: scale(2); transform: scale(2); }
.scale_x4 { -webkit-transform: scale(4); -moz-transform: scale(4); -ms-transform: scale(4); -o-transform: scale(4); transform: scale(4); }
JS:
$(function() {
$('.zoom').on("click", function() {
if ($(this).hasClass('orig')) {
$("#profile").removeClass();
} else if ($(this).hasClass('x2')) {
$("#profile").removeClass().addClass('scale_x2');
} else if ($(this).hasClass('x4')) {
$("#profile").removeClass().addClass('scale_x4');
}
});
});
Check the fiddle here: http://jsfiddle.net/sbaydakov/RhmxV/2/
Any thoughts on how to make this work, so that the whole image is viewable?
Thanks.