2012-08-10 74 views
1

我正在使用下面的代碼來等於列高度,但它沒有在其中計算填充,所以文本走出div。等高欄不添加填充

<script> 
     $(document).ready(function(){ 
      //set the starting bigestHeight variable 
      var biggestHeight = 0; 
      //check each of them 
      $('.equal').each(function(){ 
       //if the height of the current element is 
       //bigger then the current biggestHeight value 
       if($(this).height() > biggestHeight){ 
        //update the biggestHeight with the 
        //height of the current elements 
        biggestHeight = $(this).height(); 
       } 
      }); 
      //when checking for biggestHeight is done set that 
      //height to all the elements 
      $('.equal').height(biggestHeight); 

     }); 
    </script> 

回答

4

嘗試使用.outerHeight()

http://api.jquery.com/outerHeight/

  • .height() =身高
  • .outerHeight() =身高+填充+邊框
  • .outerHeight(true) =身高+填充+邊框+保證金

如果你有你的元素中的圖像,您應該只是等待圖像使用$(window).load()

$(window).load(function(){ // wait for all content and images are loaded 
     var biggestHeight = 0; 
     $('.equal').each(function(){ 
      if($(this).height() > biggestHeight){ 
       biggestHeight = $(this).height(); 
      } 
     }); 
     $('.equal').height(biggestHeight); 
    }); 
+0

已經被加載,我相信你的原則是有前途的,但不容易理解爲像我這樣的初學者。所以這是我的要求,如果你可以給我一些例子與我的代碼。 – 2012-08-10 11:49:20

+0

@pixelngrain可能只是你需要等待圖像加載。看看我編輯的答案 – 2012-08-10 12:00:17

+0

它像我的代碼一樣。不考慮填充。任何想法? – 2012-08-10 12:08:45