Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enlarging images when mouseover using Jquery?

Tags:

jquery

I am trying to enlarge the images when mouseover and reduce the size back to normal after mouseout. I have the following:

$('#image img').live("mouseover", function(){
          var $this=$(this);

          $this.attr('width','25%');
          $this.attr('height','25%');


       })

The enlarging part works fine but I am not sure how to reduce the size after mouseout. Also, I think my codes are bit ugly and not sure how to fix it. Thanks a lot.

like image 500
FlyingCat Avatar asked Dec 04 '22 02:12

FlyingCat


2 Answers

Try this: http://jsfiddle.net/FPKAP/11/ or using hover: http://jsfiddle.net/FPKAP/12/

When you will hover over the HULK it will zoomin and on mouse out zoom out.

This should help the need, lemme know if I misunderstood anything please, :)

code

$('#zoomimg').mouseenter(function() {
    $(this).css("cursor","pointer");
    $(this).animate({width: "50%", height: "50%"}, 'slow');
});

$('#zoomimg').mouseleave(function() {   
    $(this).animate({width: "28%"}, 'slow');
});

code

$('#zoomimg').hover(function() {
    $(this).css("cursor", "pointer");
    $(this).animate({
        width: "50%",
        height: "50%"
    }, 'slow');

}, function() {
    $(this).animate({
        width: "28%"
    }, 'slow');

});​
like image 198
Tats_innit Avatar answered Jan 06 '23 23:01

Tats_innit


Increasing the width and height of the image , changes the position of the image (ie) it is enlarged but not in the same position where the original image was present.

Using Scaling property will address this issue.

.transition {
    -webkit-transform: scale(2); 
    -moz-transform: scale(2);
    -o-transform: scale(2);
    transform: scale(2);
}

Fiddle link : http://jsfiddle.net/RC7kb/178/

like image 39
shali ravi Avatar answered Jan 06 '23 23:01

shali ravi