Reputation: 510
I'm having a nightmare with a simple function!
I want it to:
Code is as follows:
// 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);
}
When i run this, it appears to ignore the fact that the content has changed, and just use the original height (therefore do no animation as it thinks the height has not changed).
Please help if you can!! It's driving me nuts.
Upvotes: 4
Views: 411
Reputation: 187262
Work for me. Your bug is likely elsewhere... http://jsfiddle.net/6aBfD/
UPDATE
But that only works once. The problem is that you are relying on an element to set it's own height and read from that. But after the first run, you lock the height to a specific value. The updated link has the correct working clode, click it multiple times. I added the following:
$("#status-message")
.css("overflow","visible")
.css("height", "auto");
Now when you read the height it will be it's natural height. Then set the oveflow and height again later to lock it back down to what you want.
Upvotes: 4
Reputation: 12690
Rob,
Try the following instead of .height():
var status_origheight = $("#status-message").css('height');
Upvotes: 0