2014-12-24 35 views
1

使用load方法,我加載內容到現有的div。當內容變長時,我想增加現有div的高度以匹配加載內容。如何獲取容器高度後,我加載了html

我怎麼能找到所加載內容的高度,在情況下,如果是包裹在一個div稱爲pageContent

任何幫助嗎?

var container = $('existingDiv') 
this.container.load("Doc/chapter1/index.html", function(element){ 
       console.log($(element).innerHeight())//getting 0 
container.height(element.height())//? 
      }); 

回答

3

通常你可以做到這一點簡單的CSS(當然 - 這取決於你的DIV的複雜性 - 有時你需要JS): 您可以使用min-heightmax-heightoverflow實現這一目標。

1

難道只是使用css?

#existingDiv { 
    height: auto; 
    min-height: 250px; 
    max-height: 450px; 
    overflow: hidden; 
} 

我不知道你的css框架的樣子,但是這可能是工作。

0
#existingDiv { 
    height: auto !important; 
    min-height: <any-value>; 
    max-height: <any-value>; 
} 

試試這個。這應該給容器自動高度。但是,這又取決於您在父容器和此容器周圍的元素上應用的所有其他css

相關問題