O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Animating Resizing an Image

$("img").mouseover(function(){     $(this).animate(       {width:"200px", opacity:1}, 1000); }); $("img").mouseout(function(){     $(this).animate(       {width:"100px", opacity:.3}, 1000); });

Similar to the way you use the height and width to create a sliding effect, you can use them to create a resize animation. The difference between a slide and a resize is that the aspect ratio of the image is maintained on a resize, so the element appears to be growing or shrinking rather than being unfolded or untucked.

To create a resize animation, you need to specify both height and width in the .animate() statement, or one of them has to be auto in the CSS settings and you can only animate ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required