Get height of div with no height set in css

后端 未结 4 910
后悔当初
后悔当初 2020-11-28 01:58

Is there any way to get the height of an element if there is no CSS height rule set for the element I cannot use .height() jQuery method because it need a CSS r

4条回答
  •  抹茶落季
    2020-11-28 02:20

    Just a note in case others have the same problem.

    I had the same problem and found a different answer. I found that getting the height of a div that's height is determined by its contents needs to be initiated on window.load, or window.scroll not document.ready otherwise i get odd heights/smaller heights, i.e before the images have loaded. I also used outerHeight().

    var currentHeight = 0;
    $(window).load(function() {
        //get the natural page height -set it in variable above.
    
        currentHeight = $('#js_content_container').outerHeight();
    
        console.log("set current height on load = " + currentHeight)
        console.log("content height function (should be 374)  = " + contentHeight());   
    
    });
    

提交回复
热议问题