jquery animating different img widths

Posted by romeozor on Stack Overflow See other posts from Stack Overflow or by romeozor
Published on 2010-06-15T09:56:36Z Indexed on 2010/06/15 10:12 UTC
Read the original article Hit count: 194

Filed under:
|
|
|

Hi there,

I've been searching for an answer for a long time with no avail, so it's time to ask. I'm trying to use .animate() to change the size of an image once clicked. The first state of the image would be a thumbnail size, which would animate to the image's original size, then to a thumbnail again.

The problem is, not all the images have the same "original" size so I need a way to tell one generic function to switch to the current image's original size.

This is my current code which loads on $(window).load:

$('img[class=resize]').click(function (){
        if ($(this).width() != 150)
        {
            $(this).animate({width: '150px'}, 400);
        }
        else
        {
            $(this).animate({width: ''}, 400);
        }
    });

Now this obviously doesn't work the way I want it, because .animate() thinks when I say width: '' I want to make the width = 0. Any suggestions how I should go about this?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about image