Ton*_*bet 4 javascript jquery height
基本上
我有很少的div具有灵活的高度和固定的填充,所以很难让它们都具有相同的高度,
我这样想:
$(document).ready(function(){
$('.LevelCnt_2,.LevelCnt_2 .content,.LevelCnt_1,.LevelCnt_1 .content').outerHeight( $('header:eq(0)').outerHeight() );
console.log($('header:eq(0)').outerHeight(true));
});
Run Code Online (Sandbox Code Playgroud)
但问题是标题不是总是最高的,所以我需要
检查一个更高(考虑到有多个.content元素)
将outerHeight应用于所有人
但我找不到一个好的/美丽的方式(有一个解决方案,但我需要很多if和变量)来做到这一点
任何线索?
-编辑-
在等待的时候我想出了这个
$(document).ready(function(){
var height = 0;
$('.LevelCnt_2,.LevelCnt_2 .content,.LevelCnt_1,.LevelCnt_1 .content,header').each(function(){
if($(this).outerHeight() > height){
height = $(this).outerHeight();
}
});
$('.LevelCnt_2,.LevelCnt_2 .content,.LevelCnt_1,.LevelCnt_1 .content,header').each(function(){
$(this).outerHeight(height);
});
console.log('highest height is '+height); //it doesn't output the highest value
});
Run Code Online (Sandbox Code Playgroud)
但这些div中的大多数都是display:none问题所在?
而不是添加display none,给它们"隐藏"类并使用它.
$(function(){
var height = 0;
$('.hide').show();
$('header').each(function(){
height = Math.max( height, $(this).outerHeight() )
});
$('.hide').hide();
$('.LevelCnt_2,.LevelCnt_2 .content,.LevelCnt_1,.LevelCnt_1 .content').outerHeight(height);
console.log($('header:eq(0)').outerHeight(true));
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3955 次 |
| 最近记录: |