Zoom image inside a div

I have a div with images in thumbnails that when I zoomed in on them, I zoomed in on them, the problem is that the ones on the edges go out and do not appear whole, I suppose there has to be some form of css limit the margins of the div and that are enlarged but adapting to it. Going around I can not find anything and I can not think of any more keywords: S

In my code I use JavaScript and the "zoomIn" happens when I click on the image.
you can also click outside the group of images for a "zoomOut" If you do not like the click you can change it for mouseover .

Please read the comments in the JavaScript.

Important: each image has a data-transform_origin attribute to control the transformation of the images.