我有一个简单的功能噩梦!为什么这个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