I am working on a project in which there is an image when user clicks on image the image zoom in and when click again the image zoom out. How can I make a zoom out feature in my code here
function resizeImg (img) {
var scale = 150/100;
var pos = $(img).offset();
var clickX = event.pageX - pos.left;
var clickY = event.pageY - pos.top;
var container = $(img).parent().get(0);
$(img).css({
width: img.width*scale,
height: img.height*scale
});
container.scrollLeft = ($(container).width() / -2 ) + clickX * scale;
container.scrollTop = ($(container).height() / -2 ) + clickY * scale;
}
Try and see if the below code helps you. Demo
EDIT: Just in-case you want to do this on multiple images in same page.
DEMO
DEMO Works with multiple images
setting
zoom
attribute = 0 for all the images -->$('img').attr('zoom', 0);
if
zoom
attribute is set to0
we will makezoom
effect and set attributezoom=1
else
zoom
attribute is set to1
that is already zoomed we set the attributezoom=0
andstyle
attribute is removed to get the image back to normal.If you have multiple images this might also help you
JSfiddle: http://jsfiddle.net/95wqh/14/
JS code:
What I added
and
You dont need a lot of javascript here..just some good CSS as shown here: http://jsfiddle.net/95wqh/10/
JS:
css: