![](/img/trans.png)
[英]Why does javaScript / jQuery seem to ignore my IF statement on event bubbling?
[英]Why does this javascript (jquery) function seem to run out of order?
我有一个简单功能的噩梦!
我希望它:
代码如下:
// 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);
}
当我运行它时,它似乎忽略了内容已经改变的事实,并且只使用原始高度(因此不进行任何动画,因为它认为高度没有改变)。
如果可以的话请帮忙!! 这让我疯了。
为我工作。 您的错误可能在其他地方... http://jsfiddle.net/6aBfD/
UPDATE
但那只能工作一次 。 问题是你依靠一个元素来设置它自己的高度并从中读取。 但在第一次运行后,您将高度锁定到特定值。 更新的链接具有正确的工作clode,多次单击它。 我添加了以下内容:
$("#status-message")
.css("overflow","visible")
.css("height", "auto");
现在,当你读到高度时,它将是它的自然高度。 然后再次设置oveflow和height以将其锁定为您想要的。
抢,
尝试以下代替.height():
var status_origheight = $("#status-message").css('height');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.