I’m experimenting with the CSS zoom property, and I’m trying to basically zoom into an image while keeping it anchored at a certain point. So rather than zooming in while the point at 0,0 stays put, I’d like it to zoom from the bottom right corner instead.
So this is my attempt, but obviously it’s a little “quirky”:
Fiddle: http://jsfiddle.net/csaltyj/nJ2M8/
HTML:
<div id="overlay">
<div class="square">
<img src="http://placekitten.com/800/800" width="400" height="400" />
</div>
</div>
Javascript:
$('.square img').on('click', function() {
$('.square').animate({
zoom: '200%',
left: '-200px',
top: '-200px'
}, 200);
});
CSS:
#overlay {
overflow: hidden;
width: 400px;
height: 400px;
}
.square {
position: relative;
width: 320px;
height: 320px;
background: #333;
vertical-align: bottom;
font-size: 2em;
font-family: Impact, Arial, sans-serif;
text-transform: uppercase;
color: #fff;
}
Any way to get this to behave as I’d like it to? I need the 400,400 corner to stay put as it zooms in.
If you want to zoom to the center of the image then change:
To:
Here is a demo: http://jsfiddle.net/nJ2M8/1/
Update
Try using
transform, it’s capable of scaling an element. Here is some code I wrote a while ago to do just this:Here is a demo: http://jsfiddle.net/nJ2M8/2/ (the zoom follows your cursor and you can use your mouse-wheel to zoom in/out)