开发者

Is there a way to get the end value of an animation in jQuery?

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开发者_StackOverflow中文版 I get the end value of the animation? (The total height of the element when the animation would have been complete)


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'));


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜