2010-04-21 63 views
0

我有如下的是動畫元素的腳本:有沒有辦法在jQuery中獲取動畫的最終值?

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

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

現在假設動畫需要停止完成之前:

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

我怎樣才能獲得動畫的終值? (當動畫完成時元素的總高度)

回答

1

您可以使用.stop(true,true)清除動畫隊列,並自動「跳轉到結束」的動畫(而不是僅僅在其線停止)

你也可以保存您想要在以後使用.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')); 
+0

嗯......這是一個很好的觀點。我沒有看到有可以傳遞給'stop()'的參數 – 2010-04-21 21:33:54

0

我想我已經知道了。發佈了另一個類似的問題,並且幫助的答案是here

隨意關閉這個問題作爲一個騙局。

相關問題