Skip to content

Commit 9a8944b

Browse files
committed
added support for hidden elements, closes #12
1 parent 246820d commit 9a8944b

File tree

5 files changed

+69
-9
lines changed

5 files changed

+69
-9
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ See the [jquery.matchHeight.js demo](http://brm.io/jquery-match-height-demo).
1818
- row aware, handles floating elements
1919
- responsive, automatically updates on window resize (can be throttled for performance)
2020
- handles mixed `padding`, `margin`, `border` values (even if every element has them different)
21-
- accounts for `box-sizing`
2221
- handles images and other media (updates automatically after loading)
22+
- handles hidden or none-visible elements (e.g. those inside tab controls)
23+
- accounts for `box-sizing`
2324
- data attributes API
2425
- tested in IE8+, Chrome, Firefox, Chrome Android
2526
- can be removed when needed

jquery.matchHeight-min.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jquery.matchHeight.js

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
var $row = $(row),
7979
maxHeight = 0;
8080

81+
// ensure elements are visible to prevent 0 height
82+
var hiddenParents = $row.parents().add($row).filter(':hidden');
83+
hiddenParents.css({ 'display': 'block' });
84+
8185
// iterate the row and find the max height
8286
$row.each(function(){
8387
var $that = $(this);
@@ -93,6 +97,9 @@
9397
$that.css({ 'display': '' });
9498
});
9599

100+
// revert display block
101+
hiddenParents.css({ 'display': '' });
102+
96103
// iterate the row and apply the height to all elements
97104
$row.each(function(){
98105
var $that = $(this),

test.css

+14-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ a, a:link, a:visited, a:active, a:hover {
7272
margin: 5px 20px 5px 0;
7373
}
7474

75-
.test-remove {
75+
.btn-remove,
76+
.btn-hidden {
7677
margin: -8px 20px 0 20px;
7778
line-height: 1;
7879
border: 0;
@@ -236,4 +237,16 @@ a, a:link, a:visited, a:active, a:hover {
236237
margin-left: 0;
237238
margin-right: 0;
238239
}
240+
}
241+
242+
/* test hidden */
243+
244+
.test-hidden .hidden-items > .item-0,
245+
.test-hidden .hidden-items > .item-2 {
246+
display: none;
247+
}
248+
249+
.test-hidden .hidden-items > .item-1,
250+
.test-hidden .hidden-items > .item-3 {
251+
visibility: hidden;
239252
}

test.html

+42-3
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,22 @@
3030
});
3131

3232
// example of removing matchHeight
33-
$('.test-remove').click(function() {
33+
$('.btn-remove').click(function() {
3434
$('.items-container').each(function() {
3535
$(this).children('.item').matchHeight('remove');
3636
});
3737
});
38+
39+
// button to show hidden elements
40+
$('.btn-hidden').click(function() {
41+
$('body').removeClass('test-hidden');
42+
});
3843
});
3944

4045
})();
4146
</script>
4247
</head>
43-
<body class="test-match-height test-rows test-responsive test-border-box test-margin test-padding">
48+
<body class="test-match-height test-rows test-responsive test-border-box test-margin test-padding test-hidden">
4449
<div class="container">
4550
<h1>jquery.matchHeight Tests</h1>
4651

@@ -86,7 +91,12 @@ <h1>jquery.matchHeight Tests</h1>
8691
</div>
8792
<div class="checkbox">
8893
<label>
89-
<input class="test-remove" type="submit" value="remove matchHeight">
94+
<input class="btn-remove" type="submit" value="remove matchHeight">
95+
</label>
96+
</div>
97+
<div class="checkbox">
98+
<label>
99+
<input class="btn-hidden" type="submit" value="show hidden">
90100
</label>
91101
</div>
92102
</div>
@@ -206,6 +216,35 @@ <h3>data-mh="items-b"</h3>
206216
<p>Fixed height</p>
207217
</div>
208218
</div>
219+
220+
<div class="items-container hidden-items">
221+
<div class="item item-0">
222+
<p>display: none</p>
223+
</div>
224+
<div class="item item-1">
225+
<p>visibility: hidden</p>
226+
</div>
227+
<div class="item item-2">
228+
<div class="items-container">
229+
<div class="item item-0">
230+
<p>parent display: none</p>
231+
</div>
232+
<div class="item item-0">
233+
<p>parent display: none</p>
234+
</div>
235+
</div>
236+
</div>
237+
<div class="item item-3">
238+
<div class="items-container">
239+
<div class="item item-1">
240+
<p>parent visibility: hidden</p>
241+
</div>
242+
<div class="item item-1">
243+
<p>parent visibility: hidden</p>
244+
</div>
245+
</div>
246+
</div>
247+
</div>
209248
</div>
210249
</body>
211250
</html>

0 commit comments

Comments
 (0)