只是一个概念证明!
// attend for dom ready
$(function() {
// hide .foo before we get it's height
$('.foo').hide();
// get the height, also the one mentioned below is a good one!
var foo_height = $('.foo').height();
// see if the actual height respect our needs! esample 180px
if ( foo_height > 180 ) {
// set the height and show it!
//$('.foo').css('height', foo_height + 'px').show(); OR try
$('.foo').height( foo_height ).show();
} else {
//do something else here
}
});
这应该按预期工作!