Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 等高_Javascript_Html - Fatal编程技术网

Javascript 等高

Javascript 等高,javascript,html,Javascript,Html,我有一本书。我想做三个高度相等的垂直div。为此,我更改了每列/div中最后一个块的高度 例如,3列的命名为: .leftCenter .rightCenter .right 现在我编写了一个代码,为.leftCenter和.rightCenter设置相等的高度: var left = $('.leftCenter').height(); var center = $('.rightCenter').height(); var news = $('#newItemsList').height

我有一本书。我想做三个高度相等的垂直div。为此,我更改了每列/div中最后一个块的高度

例如,3列的命名为:

.leftCenter
.rightCenter
.right
现在我编写了一个代码,为
.leftCenter
.rightCenter
设置相等的高度:

var left = $('.leftCenter').height();
var center = $('.rightCenter').height();

var news = $('#newItemsList').height();

if (center < left)
    $('.rightCenter').height(center + (left-center));
else if (center > left)
    $('#newItemsList').height(news + (center-left));
var left=$('.leftCenter').height();
var center=$('.rightCenter').height();
var news=$('#newItemsList').height();
中频(中<左)
$('.rightCenter')。高度(中心+(左中心));
else if(中间>左侧)
$('#newItemsList')。高度(新闻+(左中));

news
是左列中最新的子块(其中有3个图像)。所以,如果中间div大于左div,我会改变新闻的高度,使它们相等,但在Chrome中不起作用。这是第一个问题。最后一个问题是:如何制作相等的3个div(包括右div)

我需要使元素在高度和宽度上相等,所以我创建了以下函数,允许您定义高度或宽度,或者其他任何东西<如果发送了最小高度并需要它与最高图元的高度匹配,则将使用代码>参照类型

elemsEqual = function (options) {
        var defaults = {
                'type' : 'height',
                'refType' : '',
                'elements' : [],
                'maxLen' : 450
            },
            settings = $.extend({}, defaults, options),
            max = 0;

        $(settings.elements.join(",")).each(function () {

            max = Math.max( max, parseInt( $(this).css(settings.type) ) );

            if(settings.refType.length) max = Math.max( max, parseInt( $(this).css(settings.refType) ) );

        });

        max = ((max < settings.maxLen) ? max : settings.maxLen);

        $(settings.elements.join(",")).css(settings.type, max + "px");
};

elemsEqual({elements : ['#selector1','#selector2', ... '#selectorN'], type : 'height'});
elemsEqual=函数(选项){
var默认值={
“类型”:“高度”,
“refType”:“,
“元素”:[],
“maxLen”:450
},
设置=$.extend({},默认值,选项),
max=0;
$(settings.elements.join(“,”).each(函数(){
max=Math.max(max,parseInt($(this.css(settings.type));
if(settings.refType.length)max=Math.max(max,parseInt($(this.css(settings.refType)));
});
max=((max
到目前为止,我有以下几点:

//Get the height of the right column since it starts at a different Y position than the other two
var right=$('.right').outerHeight(1)-$('.left').children('header').outerHeight(1)-$('.left .innav').outerHeight(1);

//Get the max of the 3
var height_max=Math.max($('.leftCenter').outerHeight(1),$('.rightCenter').outerHeight(), right);

//Apply the max to all 3
$('.rightCenter').height(height_max-3); //-3 to accommodate for padding/margin
$('.right').height(height_max);
$('.leftCenter').height(height_max);

唯一的问题是它不能使#newItemsList与父项、.leftCenter一样高。它还假设正确的div将是最大的,因此如果它不是3个div中最大的,我不知道它是否还能工作。

您是否看过以下内容:@nnnnnn这不是我需要的,因为我必须拉伸的不是完整的div,而是其中的最后一项。如果您的用户关闭了javascript怎么办?使用css可以更好地处理这一点,至少作为一个起点,并且可以在不引人注目的情况下进一步操作。