views:

9

answers:

1

I have been able to store the height for my image in a variable:

var origh4 = $('img:eq(3)').height();

However, now I would like to use that variable in the animate function like so:

$('img:first').fadeIn('normal').delay(500).animate({'height':'-=20%'}, 1500, 'easeOutQuad'); 

How do I do that?

I would like to replace the '-=20%' with 'origh4'.

Thoughts?

+1  A: 

You can just pop it in there, like this:

$('img:first').fadeIn('normal')
              .delay(500)
              .animate({ height: origh4 }, 1500, 'easeOutQuad'); 

The { height: origh4 } is normal object literal JavaScript syntax, nothing special, so just use the variable for the value of height like I have above.

Nick Craver
Thanks. This works.I had actually tried this, but what was happening is that the variables were assigned within a 'window.load()', and this statement was trying to retrieve the variables from those variables without being in the same window.load.So I simply expanded the window.load function to the entire script. Is there a downside to doing this?
marcamillion
@marcamillion - It just won't run until the window's loaded (including images), but if you're animating images you want them to be loaded so that sounds appropriate. I can't say for sure about the rest of your script though, since I don't know what it's doing :)
Nick Craver
Thanks Nick. Appreciate it.
marcamillion