views:

51

answers:

3

I can easily animate the "opacity" property

$("#blah").animate({ opactiy: 0.5}, 1000);

How can I animate the max-height css property... example:

$("#blah").animate({ "max-height": 350}, 1000);

(hint, that code doesn't work)

EDIT: To answer the questions below:

  1. There are multiple images all of css class "blah"
  2. The images are of random sizes, BUT they all have max-height: 100px
  3. When a user hovers over an image, I want it to animate the max-height (thereby smoothly un-restricting the height)
A: 

I think that you should animate the height property first and when the animation has finished replace set height to auto and reset max-height to what you need it to be:

$("#blah").animate({ "height": 350}, 1000, function(){
  $(this).css('height','auto').css('max-height',350);
});
IgalSt
Animating the height property would stretch images that are shorter than the "max" - thx for the thought though.
Timothy Khouri
+1  A: 

I'm confused by the requirement here. If you are wanting to animate something presumably it needs to be equal to the max height already. I'd do an of statement to check of an element's height equals its max height, if so remove the max-height and then animate the height. Should be the same effect

lnrbob
If I animate the height to, let's say, 1000... then I'm going to stretch images that are only 300px tall. --- BUT, if I animate the max-height, then tall images will grow, but the shorter ones would not grow past 300px... so it's not the same effect. (good thought though)
Timothy Khouri
Ah, I see, I was not anticipating the elements to be images. I think this is the way to go. Possibly there is a function that grabs the images sizes for you to reference. Sorry I can't help more!Note: in your edited question you say you would unrestricted the height which is slightly confusing. I understand it that you want to increase the restricted height. If the format is true you can just animate the height to 100%. I mention this to help avoid co fusion for other users
lnrbob
A: 

OK, so there is no way to do what I wanted... So I've had to make my own function to have generic "animation" function (from x to y in d milliseconds).

I wrote a blog post describing how I did it here: Generic "Animate" function with jQuery

I included a demo of what it can do as well. The demo link is at the bottom of the article, or for the impatient, you can just click here.

Timothy Khouri