当窗口大小大于指定宽度时,在两个浮动div上均衡高度,然后在窗口宽度低于时返回到原始高度

时间:2013-06-03 14:25:10

标签: jquery

我有正确的代码来均衡div,但我不知道"回到原来的高度"部分。

这是我到目前为止的代码:http://jsfiddle.net/5fTXZ/1/

jQuery:

// equalize height of columns
function equalHeight(group) {
    tallest = 0;
    group.each(function () {
        thisHeight = $(this).height();
        if (thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
group.height(tallest);
}

// change to original height of columns
function originalHeight(group) {
    // not sure what to put here
}

// change height based on windows size
function checkWindowSize() {
    if ($(window).width() > 767) {
        equalHeight($(".col"));
    } else {
        originalHeight($(".col"));
    }
}

jQuery(document).ready(function ($) {
    $(window).resize(checkWindowSize);
    checkWindowSize();
});

当宽度大于767px时,您可以看到是否更改输出的窗口大小,div将在高度上相等。如果你将它改回到767px以下的宽度,它只会调用我尚未想到的空函数。

1 个答案:

答案 0 :(得分:1)

Working jsFiddle Demo

只需从元素中移除height

function originalHeight(group) {
    group.css('height', '');
}