tags:

views:

18

answers:

2

I have a script that animates an element as follows:

var item_height = $('#item').height();
$('#item').height(0);

$('#item').animate({ height: item_height });

Now suppose the animation needs to be stopped before it is complete:

$('#item').stop();

How can I get the end value of the animation? (The total height of the element when the animation would have been complete)

A: 

I think I figured it out. There was another similar question posted and the answer that helped is here.

Feel free to close this question as a dupe.

George Edison
+1  A: 

You can use .stop(true,true) to clear the animation queue and automatically "jump to the end" of the animation (instead of just stopping in its line)

You could also save the value you want later using .data():

var $item = $('#item'); // rather than query 3 times, just save this
var item_height = $item.height();
$item.data('origHeight', item_height);
$item.height(0);

$item.animate({ height: item_height });

// later
$item.stop(); 
$item.height($item.data('origHeight'));
gnarf
Hmmm... that's a very good point. I hadn't seen that there were parameters you could pass to `stop()`
George Edison