jquery-match-height icon indicating copy to clipboard operation
jquery-match-height copied to clipboard

Setting Height of Element by target(should consider/detect byRow)

Open Nukro opened this issue 7 years ago • 3 comments

Hello Guys

I am trying to set the height of some divs to a specific target. At the first I am setting the height for the prospective target div.

$('.wrapper').matchHeight();

Now I want to set the height of my other divs by the height of the wrapper element. So I use the target option:

$('.kennzahlen > .dekobild').matchHeight({ target: $('.wrapper') });

This works only for the first row. It always takes the height of the first wrapper element he finds. It doesn't consider the height of the wrapper per row. Is it possible to achieve this somehow?

Nukro avatar Nov 23 '16 09:11 Nukro

This is the expected behaviour of the target option, it sets every selected element to the first matched target element. There's currently no built in option for target to work by row.

You should maybe take a look at the rows function and make a copy, then iterate the rows and apply matchHeight to the row with the target selected from the row.

liabru avatar Nov 23 '16 10:11 liabru

Thanks for your answer.

I have tried this, but this doesn't really work:

var rows = $.fn.matchHeight._rows($('.wrapper'));

$.each(rows, function(i, row) { row.matchHeight(); row.parent().siblings(".kennzahlen > .dekobild").matchHeight({target: row}); });

My Markup looks like this: bildschirmfoto 2016-11-23 um 11 49 52

Nukro avatar Nov 23 '16 10:11 Nukro

@Nukro I think you were close.

Here's what I did that worked:

var rows = $.fn.matchHeight._rows($('.row'));

$.each(rows, function(i, row) {
    $matchTarget = row.closest('.wrap').find('.target');
    row.matchHeight({
        target: $matchTarget
    });
});

And html would look like this:

<div class="wrap">
    <div class="row">
        Some Content
    </div>
    <div class="row target">
        Some Other Content
    </div>
</div>

skillmatic-co avatar Jan 06 '17 17:01 skillmatic-co