2014-10-07 60 views
0

我試圖讓ul(ul.testimonial)等於它的最高的孩子李負載和窗口調整大小的高度。一個潛在的問題是,它是絕對的div,並使用查詢週期分階段進行。我加載的是劇本雖然WordPress的,但它似乎並不奏效: -jQuery負載和調整大小的最高孩子的父高度

<script> 
function equalHeight(group) { 
tallest = 0; 
group.each(function() { 
    thisHeight = $(this).height(); 
    if(thisHeight > tallest) { 
     tallest = thisHeight; 
    } 
}); 
group.height(tallest); 
} 

jQuery(function($){ 
$(window).on('load', function(){ 
equalHeight($("ul.testimonial")); 
}); 
}); 

$(window).bind('resize', function() { 
//$('ul.testimonial').css('height','auto'); 
equalHeight($("ul.testimonial")); 
}); 
</script> 

可有人請讓我知道什麼是錯的代碼或者一個更好的方式來做到這一點?

感謝

Glennyboy

回答

0

我發現這個代碼到底爲我工作。我確信有更好的,但它非常小,jt工作。

<script type="text/javascript"> 
jQuery(document).ready(updateHolderSize); 
jQuery(window).resize(updateHolderSize); 

function updateHolderSize() { 
var max = 0; 
jQuery("ul.testimonial li").each(function() { 
    max = Math.max(max, jQuery(this).height()); 
}); 
jQuery("ul.testimonial").height(max); 
} 
</script> 

對於我在Wordpress中的實現,這隻適用於'jQuery'而不是'$'。

乾杯 Glennyboy

+0

使$工作包裝成'的jQuery(函數($){/ *使用$這裏* /});' – 2016-03-12 15:03:06

相關問題