我有几个 <div>
元素彼此相邻,我想将它们的高度与最高的元素相匹配。目前我是这样做的:
jQuery(function($) {
var maxHeight = 0;
$( ".services-area").each (function (index ) {
if (maxHeight < $( this ).height()) {
maxHeight = $( this ).height();
}
});
$( ".services-area").each (function (index ) {
$( this ).height(maxHeight);
});
})
有没有更好的方法来实现这个结果?
最佳答案
就我个人而言,我这样做:
$.fn.sameHeight = function(){
var max = 0;
this.each(function(){
max = Math.max($(this).height(),max);
});
return this.height(max);
};
然后我可以随时调用它
$('.column').sameHeight();
请参阅此处的实时示例 http://jsfiddle.net/Panomosh/t6xsjef7/
关于javascript - 匹配元素的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30375336/