-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper-equalHeights.js
47 lines (40 loc) · 1.18 KB
/
helper-equalHeights.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* helper-equalHeights.js - v2.0.0
* https://github.com/brandung/helper-equalHeights.git
*
* Copyright brandung GmbH & Co.KG
* http://www.brandung.de/
* MIT License (MIT)
*
* @require: jQuery
*
* @param {object} block object, e.g. $('ul')
* @param {string} selector, e.g. 'li'
*/
Brandung.Helpers.equalHeights = function (group, item) {
if (!group.length) return;
var s = document.body || document.documentElement, s = s.style;
if( s.webkitFlexWrap == '' || s.msFlexWrap == '' || s.flexWrap == '' ) return true;
var $list = group,
$items = $list.find(item),
setHeights = function ()
{
$items.css( 'height', 'auto' );
var perRow = Math.floor( $list.width() / $items.width() );
if( perRow == null || perRow < 2 ) return true;
for( var i = 0, j = $items.length; i < j; i += perRow )
{
var maxHeight = 0,
$row = $items.slice( i, i + perRow );
$row.each( function()
{
var itemHeight = parseInt( $( this ).outerHeight() );
if ( itemHeight > maxHeight ) maxHeight = itemHeight;
});
$row.css( 'height', maxHeight );
}
};
setHeights();
$(window).on( 'resize', setHeights );
$list.find('img').on( 'load', setHeights );
};