我有一個簡單的功能噩夢!爲什麼這個javascript(jquery)函數看起來運行不正常?
我希望它:
- 讀一個div與現有內容的高度,它
- 更新與新的內容股利(供給函數)
- 讀出的高度的DIV應該是,但將其設置爲原始高度。
- 動畫div的高度以調整和適應新內容。
代碼如下:
// function to display status content by animating the height of the status message
function slideStatus(content){
// get current height
var status_origheight = $("#status-message").height();
// insert new content
$("#status-message").html(content);
// get new height
var status_newheight = $("#status-message").height();
// set the height to the orig value, hiding overflow content
$("#status-message").height(status_origheight).css("overflow","hidden");
// animate the div to the new height
$("#status-message").animate({height:"+="+(status_newheight - status_origheight)+""}, 1000);
}
當我運行它,它似乎忽略了一個事實,即內容已經改變,只是使用原來的高度(因此也沒有動畫,因爲它認爲,高度沒有改變)。
請幫助,如果你可以!這讓我瘋狂。
Squeegy你的傳奇! 這樣做的技巧 - 溢出規則仍然是從上一次運行的div設置。 非常感謝! – Rob 2010-09-02 17:17:57