Skip to content Skip to sidebar Skip to footer

Zoom Out Image In Center Using Jquery?

I want to animate the image and keep it exactly in the center of the currently opened window. I have tried the following, but it is not working please suggest how to improve the co

Solution 1:

It really depends on the rest of your markup. Your code works for me this way:

(check the demo)

HTML:

<divid="imgContainer"><imgsrc="your-image.jpg"></div>

CSS:

html, body, #imgContainer {
    width:100%; height:100%;
}
#imgContainer > img {
    position:absolute; top:0; right:0; bottom:0; left:0;
    margin:auto;
    width:200px;
    max-width:100%;
    max-height:100%;
}

jQuery:

$('#imgContainer > img').on('click',function(){
   var h = $(this).height();
   var w = $(this).width();

    //get div dimensionsvar div_h =$('#imgContainer').height();
    var div_w =$('#imgContainer').width();

    var  pY = Math.round((div_h - h) / 2) + 'px';
    var  pX = Math.round((div_w - w) / 2) + 'px';

    $(this).animate({
        opacity:"1", 
        zoom: '500%'
    }, 1000)

});

Solution 2:

You can use jQuery zoom plugin. Following is the usage example:

// Example:
$(document).ready(function(){
    $('a.photo').zoom({url: 'photo-big.jpg'});
});

// Using ColorBox with Zoom
$(document).ready(function(){
    $('a.photo').zoom({
        url: 'photo-big.jpg', 
        callback: function(){
            $(this).colorbox({href: this.src});
        }
    });
});

Post a Comment for "Zoom Out Image In Center Using Jquery?"