2014-12-20 104 views
0

我试图获取父容器高度,然后将其应用于子容器内,其中的最终结果是对窗口大小进行响应,并且禁用此功能下面的窗口大小768px通过获取父容器高度并将其应用于子元素来设置相等的盒子高度

请参阅的jsfiddle:http://jsfiddle.net/8vks5ubj/9/embedded/result/

jQuery('.common-height').each(function(){ 

var highestBox = 0; 
jQuery('.center', this).each(function(){ 

    if($(this).outerHeight() > highestBox) 
     highestBox = jQuery(this).outerHeight(); 
}); 

jQuery('.center',this).outerHeight(highestBox); 

}); 

会很感激的任何帮助。

感谢

回答

0

试试这个:

function setHeight() { 
    var arr = [], 
     $elems = $('.someblock'); // Place there your divs 

    $elems.each(function() { 
     arr.push($(this).outerHeight()); // Divs height moved to array 
    }); 

    $elems.css('height', Math.max.apply(0, arr)); //Find max value and apply css height 
}; 

($(window).width() < 768) && setHeight(); 
//When document loaded and window width less than 768px -> call function 

$(window).resize(function(){ 
    ($(window).width() < 768) && setHeight(); 
}); 

在行动观察:JSFiddle(只是调整与div的窗口)

附:对不起,我的英文;)

相关问题