jQuery - Set min-height of div

前端 未结 3 1905
野的像风
野的像风 2020-12-09 16:14

This is probably really easy for most of you. But I\'m in need of a small snippet that looks up the current height of a div (the div has a dynamic height based on the conten

3条回答
  •  一整个雨季
    2020-12-09 16:39

    just a proof of concept!

         // 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
                }
    });
    

    this should work as expected!

提交回复
热议问题