jquery animating different img widths
- by romeozor
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?